7

Ok, so kind of getting nowhere here. Before I posted a problem with my Mac M1 having linker issues with Rust Diesel and got nothing. So I spun up an Ec2 instance and tried to run this crate here and got the following:

error: linking with `cc` failed: exit status: 1
...
 = note: /usr/bin/ld: cannot find -lpq

I've installed the following:

sudo yum update -y
sudo yum install git -y
sudo yum groupinstall "Development Tools" -y
sudo yum install cmake -y
sudo yum install postgresql-libs -y

Seriously, how are people managing to get this crate running?

kmdreko
  • 42,554
  • 6
  • 57
  • 106
max89
  • 443
  • 5
  • 18

3 Answers3

9

From the Diesel Getting Started guide:

If you run into an error like:

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

This means you are missing the client library needed for a database backend – mysqlclient in this case. You can resolve this issue by either installing the library (using the usual way to do this depending on your operating system) or by excluding the undesired default library with the --no-default-features flag.

By default diesel depends on the following client libraries:

If you are not sure on how to install those dependencies please consult the documentation of the corresponding dependency or your distribution package manager.

For example, if you only have PostgreSQL installed, you can use this to install diesel_cli with only PostgreSQL:

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

The error "cannot find -lpq" is your linker telling you that it cannot find the PostgreSQL client library.

eggyal
  • 122,705
  • 18
  • 212
  • 237
  • I couldn't install ```libpq``` on the EC2 but I did install ```postgresql-libs``` and I'm getting the same error. I also have these drivers on my mac but it results in ```dyld: Symbol not found: _PQconnectdb``` I have done postgres dev with python in the past, this diesel crate seems to be the most brittle thing I've ever worked with – max89 Jan 30 '22 at 13:47
  • @max89 Do the answers [here](https://stackoverflow.com/q/70313347/2189130) help you out? – kmdreko Jan 31 '22 at 01:36
3

The issue was caused by a missing library. For Linux

sudo apt install libpq-dev
cargo install diesel_cli --no-default-features --features postgres

For Windows, Check the version of rust you have installed

rustup --version

then copy the libq.lib from

C:\Program Files\PostgreSQL\14\lib

to

C:\Users\"Your User"\.rustup\toolchains\"Your version of Rust-Nightly or Stable"\lib\rustlib\x86_64-pc-windows-msvc\lib

Worked for me !!

Tanka
  • 61
  • 6
1

I'm on Fedora 36. The problem seemed to be that there were 2 versions of Postgres in my PC, and diesel couldn't figure out which library to use. So here's what solved it:

sudo dnf remove postgresql10-libs
sudo dnf install postgresql14-libs
sudo dnf install postgresql14-devel

Edit: this worked for a bit, but then broke again. I fixed it with:

sudo dnf remove postgresql14-devel
sudo dnf install libpq-devel.x86_64
willsbit
  • 11
  • 3
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/32197301) – Terry Raimondo Jul 13 '22 at 11:45