< 返回版块

C-Jeril 发表于 2023-12-25 14:05

Tags:cargo, dll, 0xc000007b

##现在遇到的问题是cargo run的情况下,遇到0xc000007b,目前不知道是环境缺失了什么导致的问题 最早之前报的是 error: linking with link.exe failed: exit code: 1181 = note: LINK : fatal error LNK1181: 无法打开输入文件“libpq.lib”, 后来重装了postgreSQL,重新定位了安装文件夹等。 后来提示缺失DLL文件: target\debug\backend-rust.exe (exit code: 0xc0000135, STATUS_DLL_NOT_FOUND) 尝试在taget文件夹内,用depend.exe分析出缺失的DLL,尝试放了进去: libintl-9.dll libwinpthread-1.dll libssl-3-x64.dll libiconv-2.dll libcrypto-3-x64.dll

最后还是就变成了报错0xc000007b。 也就是所有的重装都已经试过了,不确定现在到底是什么文件或者依赖项目导致的问题

Cargo.toml Configuration

[package]
name = "backend"
version = "0.1.0"
edition = "2021"

[dependencies]
axum = "^0.7"
tokio = { version = "^1", features = ["full"] }
serde = { version = "^1", features = ["derive"] }
serde_json = "^1"
diesel = { version = "^2.1.4", features = ["postgres", "r2d2", "chrono"] }
dotenv = "^0.15"
postgres = "^0.17.5"

main.rs
use dotenv::dotenv;
use std::env;
use std::net::SocketAddr;
use tokio::net::TcpListener;

use diesel::{
pg::PgConnection,
prelude::*,
r2d2::{ConnectionManager, Pool},
};

use axum::{
extract::Extension,
routing::{get, post}, // 如果您没有使用 post,/* */可以注释掉
// ...其他 axum 导入...
serve, // 导入 serve 函数
Router,
};

// Database connection pool type // 定义连接池类型
pub type DbPool = Pool<ConnectionManager>;

// Function to establish a connection pool
fn establish_connection() -> DbPool {
dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let manager = ConnectionManager::::new(database_url);
Pool::new(manager).expect("Failed to create pool.")
}

#[tokio::main]
async fn main() {
// 创建数据库连接池 // Set up the database connection pool
let pool = establish_connection();
// 创建 Axum 应用并传递连接池作为共享状态
// Create Axum application and pass the connection pool as shared state
let app = Router::new()
.route("/login", get(login))
.route("/dashboard", get(dashboard))
.route("/cardtable", get(card_table))
.route("/cardtable/drawcards", get(draw_cards))
.route("/knowmore", get(know_more))
.route("/knowmore/positivepsychology", get(positive_psychology))
.route("/profile", get(profile))
.route("/user", get(user_home))
.route("/user/info", get(user_info))
.route("/user/setting", get(user_setting))
// ...其他路由...other routes
.layer(Extension(pool));

// Start the server
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
let listener = TcpListener::bind(addr)
    .await
    .expect("Failed to bind to address");
println!("Server running at http://{}", addr);
serve(listener, app).await.expect("Failed to start server");
}

// ...您的异步处理函数...
// 使用 conn 执行数据库操作
async fn login() -> &'static str {
"这里是登录界面"
}

async fn dashboard() -> &'static str {
"这里是仪表盘页面"
}

评论区

写评论
jerryshell 2023-12-28 08:14

解决方案有很多啊,用 Google 搜关键字 rust diesel libpq 就能搜出一堆

比如我这用下面这行命令就能编译成功

cargo rustc --release -- -L C:\\Users\\XXX\\Downloads\\postgresql-16.1-1-windows-x64-binaries\\pgsql\\lib
jerryshell 2023-12-28 07:53
pub type DbPool = Pool<ConnectionManager>;

这行就已经报错了,ConnectionManager 少泛型

作者 C-Jeril 2023-12-27 12:30

--
👇
jerryshell: https://www.markdown.xyz/basic-syntax

用 Markdown 语法规范一下帖子格式,要不然没人看得懂你的问题 好的,已经修改好了,感谢

作者 C-Jeril 2023-12-27 12:28

--
👇
jerryshell: https://www.markdown.xyz/basic-syntax

用 Markdown 语法规范一下帖子格式,要不然没人看得懂你的问题

--

--

thx马上修改

jerryshell 2023-12-25 15:07

https://www.markdown.xyz/basic-syntax

用 Markdown 语法规范一下帖子格式,要不然没人看得懂你的问题

1 共 6 条评论, 1 页