无法在 Mac M1 上链接 libpq

max*_*x89 8 postgresql macos libpq rust-diesel

我一直在尝试在我的 Macbook M1 上运行 Rust Diesel crate,但它不起作用。编译的最后部分因以下错误而中断:

\n
  = note: ld: warning: ignoring file /usr/local/Cellar/libpq/14.1/lib/libpq.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64\n          Undefined symbols for architecture arm64:\n
Run Code Online (Sandbox Code Playgroud)\n

当我得到信息时,libpq我得到以下信息:

\n
maxwellflitton@Maxwells-MacBook-Pro vanguard % brew info libpq                                                           \nlibpq: stable 14.1 (bottled) [keg-only]\nPostgres C API library\nhttps://www.postgresql.org/docs/14/libpq.html\n/usr/local/Cellar/libpq/14.1 (2,335 files, 27.8MB)\n  Poured from bottle on 2022-01-09 at 00:14:32\nFrom: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/libpq.rb\nLicense: PostgreSQL\n==> Dependencies\nRequired: krb5 \xe2\x9c\x94, openssl@1.1 \xe2\x9c\x94\n==> Caveats\nlibpq is keg-only, which means it was not symlinked into /usr/local,\nbecause conflicts with postgres formula.\n\nIf you need to have libpq first in your PATH, run:\n  echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc\n\nFor compilers to find libpq you may need to set:\n  export LDFLAGS="-L/usr/local/opt/libpq/lib"\n  export CPPFLAGS="-I/usr/local/opt/libpq/include"\n\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试使用以下命令进行安装:

\n
RUSTFLAGS='-L /usr/local/Cellar/libpq/14.1/lib' cargo install diesel_cli --no-default-features --features postgres --force\n
Run Code Online (Sandbox Code Playgroud)\n

但我仍然遇到同样的错误。擦除整个内容并重新开始会更容易吗?如果是,我该怎么做?互联网上使用 M1 的其他人似乎能够通过简单的brew install libpq. 我以前的 intel mac 从未出现过任何问题。我~/.cargo/config.toml的配置如下:

\n
[target.aarch64-apple-darwin]\nrustflags = '-L /usr/local/Cellar/libpq/14.1/lib -L /opt/homebrew/lib'\n
Run Code Online (Sandbox Code Playgroud)\n

mat*_*eos 8

令人惊讶的是这有效

  • brew install postgresql libpq
  • cargo clean
  • cargo build
  • cargo install diesel_cli --no-default-features --features postgres

我认为这与安装必要的依赖项之前的安装有关diesel-cli。清理货物依赖项并重新安装对我有用