ld:在macOS中构建rust时未找到-lpq的库

kdfy810k  于 2023-02-04  发布在  Mac
关注(0)|答案(5)|浏览(262)

当我在macOS中使用apple silicon构建我的rust项目时,使用以下命令:

CARGO_HTTP_MULTIPLEXING=false cargo build

显示如下错误:

= note: ld: library not found for -lpq
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

我试过安装

brew install libpq
brew link --force libpq

我还是没有修复这个问题,我应该怎么做来修复这个问题?是不是PostgreSQL库现在不支持Apple Sillicon(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"
sycxhyv7

sycxhyv71#

首先,我运行以下命令:

brew install libpq
brew link --force libpq

然后:

PQ_LIB_DIR="$(brew --prefix libpq)/lib"

cargo install diesel_cli --no-default-features --features postgres

对我很有效。
macOS:大苏尔11.5

8zzbczxx

8zzbczxx2#

我在我的项目中使用Diesel ORM:https://github.com/EstebanBorai/estebanborai.com,这就是我如何设置支持Diesel的项目。
1.使用Homebrew安装libpq

brew install libpq && brew link --force libpq

1.然后将库添加到PATH中

echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc

1.最后安装Diesel CLI

cargo install diesel_cli --no-default-features --features postgres

货物装运

这是我的Cargo.toml文件,用于版本参考:

# -- snip --

[dependencies]
diesel = { version = "1.4.4", features = ["chrono", "postgres", "r2d2", "uuidv07"] }
r2d2 = "0.8.9"

# -- snip --

柴油CLI

这是Diesel CLI版本的输出

< diesel --version
> diesel 1.4.1
lmyy7pcs

lmyy7pcs3#

我用以下公式求解:

cargo clean

后来

cargo build
aiazj4mn

aiazj4mn4#

看起来路径在BigSur和/或Monterrey中被移动了。我通过显式指定库路径解决了这个问题。
IE在CLI中运行rustc:

rustc -L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib ./main.rs

您也可以在RUSTFLAGS环境变量中指定它,即:

export RUSTFLAGS='-L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib'

然后运行:

rustc ./main.rs

或:

cargo build

在您的示例中,您可以执行以下操作:

CARGO_HTTP_MULTIPLEXING=false RUSTFLAGS='-L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib'
 cargo build
sycxhyv7

sycxhyv75#

我在运行我的货物构建时遇到了这个错误消息的问题:

= note: ld: library not found for -lpq
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

我解决这个问题的方法是使用brew安装所需的postgres C库

brew install libpq
brew link --force libpq

如果您像我一样使用fish,我还添加了如下链接:fish_add_path /opt/homebrew/opt/libpq/bin

相关问题