Dol*_*hin 22 linker-errors rust
当我使用以下命令在 macOS 中使用 apple sillicon 构建 rust 项目时:
CARGO_HTTP_MULTIPLEXING=false cargo build
Run Code Online (Sandbox Code Playgroud)
显示这样的错误:
= note: ld: library not found for -lpq
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
我已经尝试安装
brew install libpq
brew link --force libpq
Run Code Online (Sandbox Code Playgroud)
仍然没有解决这个问题,我应该怎么做才能解决这个问题?是不是 PostgreSQL 库现在不支持 Apple Silicon(Apple M1 Pro)?这是我的项目依赖项:
[package]
name = "reddwarf_dict"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rocket = { version = "0.5.0-rc.1", features = ["json"] }
serde = { version = "1.0.64", features = ["derive"] }
serde_json = "1.0.64"
# database
diesel = { version = "1.4.7", features = ["postgres"] }
dotenv = "0.15.0"
chrono = "0.4"
log = "0.4"
env_logger = "0.9.0"
config = "0.11"
rust_wheel = "0.1.0"
Run Code Online (Sandbox Code Playgroud)
Arc*_*rco 33
首先,我运行这些命令:
brew install libpq
brew link --force libpq
Run Code Online (Sandbox Code Playgroud)
然后:
PQ_LIB_DIR="$(brew --prefix libpq)/lib"
cargo install diesel_cli --no-default-features --features postgres
Run Code Online (Sandbox Code Playgroud)
这个对我有用。
macOS:大苏尔 11.5
jos*_*jan 18
我用以下方法解决了它:
cargo clean
Run Code Online (Sandbox Code Playgroud)
之后
cargo build
Run Code Online (Sandbox Code Playgroud)
Est*_*rai 13
我在我的项目中使用 Diesel ORM: https: //github.com/EstebanBorai/estebanborai.com这就是我设置项目以支持 Diesel 的方式。
libpq使用自制程序安装brew install libpq && brew link --force libpq
Run Code Online (Sandbox Code Playgroud)
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc
Run Code Online (Sandbox Code Playgroud)
cargo install diesel_cli --no-default-features --features postgres
Run Code Online (Sandbox Code Playgroud)
这是我的Cargo.toml版本参考文件:
# -- snip --
[dependencies]
diesel = { version = "1.4.4", features = ["chrono", "postgres", "r2d2", "uuidv07"] }
r2d2 = "0.8.9"
# -- snip --
Run Code Online (Sandbox Code Playgroud)
这是我的 Diesel CLI 版本的输出
# -- snip --
[dependencies]
diesel = { version = "1.4.4", features = ["chrono", "postgres", "r2d2", "uuidv07"] }
r2d2 = "0.8.9"
# -- snip --
Run Code Online (Sandbox Code Playgroud)
BigSur 和/或蒙特雷的路径似乎已移动。我通过明确指定库路径解决了这个问题。
IE 在 CLI 中运行 rustc:
rustc -L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib ./main.rs
Run Code Online (Sandbox Code Playgroud)
您还可以在 RUSTFLAGS 环境变量中指定它,IE:
export RUSTFLAGS='-L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib'
Run Code Online (Sandbox Code Playgroud)
然后运行:
rustc ./main.rs
Run Code Online (Sandbox Code Playgroud)
或者:
cargo build
Run Code Online (Sandbox Code Playgroud)
在你的例子中,你可以这样做:
CARGO_HTTP_MULTIPLEXING=false RUSTFLAGS='-L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib'
cargo build
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8515 次 |
| 最近记录: |