8

I've been trying to run the Rust Diesel crate on my Macbook M1 and it doesn't work. The final part of the compilation gets broken by the following error:

  = 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
          Undefined symbols for architecture arm64:

When I get the info for libpq I get the following:

maxwellflitton@Maxwells-MacBook-Pro vanguard % brew info libpq                                                           
libpq: stable 14.1 (bottled) [keg-only]
Postgres C API library
https://www.postgresql.org/docs/14/libpq.html
/usr/local/Cellar/libpq/14.1 (2,335 files, 27.8MB)
  Poured from bottle on 2022-01-09 at 00:14:32
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/libpq.rb
License: PostgreSQL
==> Dependencies
Required: krb5 ✔, openssl@1.1 ✔
==> Caveats
libpq is keg-only, which means it was not symlinked into /usr/local,
because conflicts with postgres formula.

If you need to have libpq first in your PATH, run:
  echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc

For compilers to find libpq you may need to set:
  export LDFLAGS="-L/usr/local/opt/libpq/lib"
  export CPPFLAGS="-I/usr/local/opt/libpq/include"

I've tried installing with the following command:

RUSTFLAGS='-L /usr/local/Cellar/libpq/14.1/lib' cargo install diesel_cli --no-default-features --features postgres --force

But I still get the same error. Will it just be easier to wipe the whole thing and start again and if so how would I do this? Other people on the internet using the M1 seem to be able to get round the problem with a simple brew install libpq. Never had any issues with my previous intel mac. My ~/.cargo/config.toml has the following configuration:

[target.aarch64-apple-darwin]
rustflags = '-L /usr/local/Cellar/libpq/14.1/lib -L /opt/homebrew/lib'
max89
  • 443
  • 5
  • 18
  • Does this answer your question? [Problem trying to install diesel (Mac air m1)](https://stackoverflow.com/questions/70383711/problem-trying-to-install-diesel-mac-air-m1) – weiznich Jan 10 '22 at 09:40
  • Hi Max, I am just reading your book right now, was funny seeing your name in this post. I have the same problem as you. Was this solved yet? When I try to install diesel I end up with this message: "ld: warning: ignoring file /usr/local/Cellar/libpq/14.5/lib/libpq.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64" – Mactov Sep 30 '22 at 16:46

5 Answers5

8

Surprisingly this worked

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

I think it had to do with installing diesel-cli before installing the necessary dependencies. Cleaning the cargo dependencies and reinstalling worked for me

mateos
  • 1,405
  • 1
  • 17
  • 26
4

Encountered a similar problem, and the issue was coming from my brew config (I restored my filesystem from my mac Intel) :

❯ brew config
...
macOS: 12.6-x86_64
...

Therefore, brew was downloading packages built for intel processors. I uninstalled and reinstalled brew following their website and now brew config is correct:

❯ brew config
...
macOS: 12.6-arm64
...

Hope this helps!

2

on my M1 mac, I installed the postgresql client and library with brew:

brew install postgresql libpq

and attempted to install diesel_cli again, this time it worked fine:

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

for some reason, simply installing libpq was not enough to install diesel_cli, i had to install the postgres library and the client.

Phil Loctaux
  • 596
  • 6
  • 8
  • I was able to build diesel but when I try to run it I still get an error ``` Finished release [optimized] target(s) in 22.52s Replacing /Users/a/.cargo/bin/diesel Replaced package `diesel_cli v1.4.1` with `diesel_cli v1.4.1` (executable `diesel`) ➜ git:(master) ✗ diesel setup dyld[72305]: symbol not found in flat namespace '_PQclear' [2] 72305 abort diesel setup ``` – Anant Apr 13 '22 at 15:20
1

I have a Mac M1 and installed both postgresql and libpq with brew

I eventually succeeded in installing diesel_cli with these lines in my ~/.cargo/config.toml file

[target.aarch64-apple-darwin]
rustflags = '-L /opt/homebrew/opt/libpq/lib -L /opt/homebrew/lib'

source was https://github.com/diesel-rs/diesel/issues/2605

Mactov
  • 93
  • 2
  • 8
  • This is what fixed the error for me when attempting to build Lemmy (`lemmy_server` crate) locally on a Mac M2 Max – Sparrow1029 Aug 08 '23 at 18:06
0

I'm trying to compile a rust project I built. It's because of the target, its trying to compile for arm64 however the dylib for postgres its using is for x64_86. So it throws this error.

I tried to reinstall libpq but still have the same error—might compile it for x64_86 and run it through rosetta.

This is the exact error I have:

Undefined symbols for architecture arm64:
            "_PQclear", referenced from:
ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

I ended up reinstalling postgresql and libpq with arm64 variants while preserving x64_86 for projects that aren't updated and need to use x64_86 code:

https://codetinkering.com/switch-homebrew-arm-x86/