{"id":1215,"hash":"ddc67bd9d5ce3229d62f63adfbdd0a865d512d2f3493cfed0ee5052ab2dd0d42","pattern":"cannot link libpq on Mac M1","full_message":"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:\n\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\nWhen I get the info for libpq I get the following:\n\nmaxwellflitton@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 ✔, openssl@1.1 ✔\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\nI've tried installing with the following command:\n\nRUSTFLAGS='-L /usr/local/Cellar/libpq/14.1/lib' cargo install diesel_cli --no-default-features --features postgres --force\n\nBut 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:\n\n[target.aarch64-apple-darwin]\nrustflags = '-L /usr/local/Cellar/libpq/14.1/lib -L /opt/homebrew/lib'","ecosystem":"cargo","package_name":"postgresql","package_version":null,"solution":"Surprisingly this worked\n\nbrew install postgresql libpq\ncargo clean\ncargo build\ncargo install diesel_cli --no-default-features --features postgres\n\nI think it had to do with installing diesel-cli before installing the necessary dependencies. Cleaning the cargo dependencies and reinstalling worked for me","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/70637566/cannot-link-libpq-on-mac-m1","votes":10,"created_at":"2026-04-19T04:52:37.214686+00:00","updated_at":"2026-04-19T04:52:37.214686+00:00"}