Diesel: failed to compile `diesel_cli v0.6.1`./usr/bin/ld: cannot find -lpq, cannot find -lsqlite3

Created on 10 May 2016  路  17Comments  路  Source: diesel-rs/diesel

Hi, I'm very love rust and very interesting in your project. Currently I'm building a simulation training system using iron, diesel and other rust crates. But when I try to install diesel_cli followed your "getting start" doc, using "cargo install diesel_cli" in bash. But it failed:
2016-05-10 11-25-39

error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/fuying/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/tmp/cargo-install.j1yQaQUZOGv2/release/diesel.0.o" "-o" "/tmp/cargo-install.j1yQaQUZOGv2/release/diesel" "-Wl,--gc-sections" "-pie" "-Wl,-O1" "-nodefaultlibs" "-L" "/tmp/cargo-install.j1yQaQUZOGv2/release" "-L" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps" "-L" "/usr/lib" "-L" "/home/fuying/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libdotenv-695bff8444756e3d.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libdiesel-8d0a380195f8199e.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libregex-9d62d4e55570bda2.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libthread_local-e8b3e196ecb61c7c.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libchrono-80703cb7572bf802.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libnum-f6961afa9fa1a02b.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libthread_id-bcd46c79a620a618.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libbyteorder-f3f7821512ca2fd0.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libtime-750bfdd52feafcb7.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libaho_corasick-e528bf4fdf3954ff.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libregex_syntax-88bc923660c879aa.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libutf8_ranges-5c6a6dacba3be7ce.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libpq_sys-951a1cd1f21ad686.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/liblibsqlite3_sys-755891849c290f5c.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libnum_iter-50df698bc905252c.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libnum_integer-52fdddf28cd8e924.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libnum_traits-555e3a6260c26680.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libmemchr-c555f740a543880f.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/liblibc-6b483f9a7097e9a4.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libclap-9bc84d3c3d1b047d.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libstrsim-cb9b0c8013c1be6f.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libansi_term-60226d3f8fc96ac9.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libbitflags-e61ad67c3301e77d.rlib" "/tmp/cargo-install.j1yQaQUZOGv2/release/deps/libvec_map-f8aa344cc08e9b03.rlib" "/home/fuying/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cb705824.rlib" "/home/fuying/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-cb705824.rlib" "/home/fuying/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-cb705824.rlib" "/home/fuying/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-cb705824.rlib" "/home/fuying/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-cb705824.rlib" "/home/fuying/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-cb705824.rlib" "/home/fuying/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-cb705824.rlib" "/home/fuying/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-cb705824.rlib" "-l" "pq" "-l" "sqlite3" "-l" "sqlite3" "-l" "sqlite3" "-l" "util" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util" "-l" "compiler-rt"
note: /usr/bin/ld: cannot find -lpq
/usr/bin/ld: cannot find -lsqlite3
/usr/bin/ld: cannot find -lsqlite3
/usr/bin/ld: cannot find -lsqlite3
collect2: error: ld returned 1 exit status

error: aborting due to previous error
error: failed to compile `diesel_cli v0.6.1`, intermediate artifacts can be found at `/tmp/cargo-install.j1yQaQUZOGv2`

Caused by:
  Could not compile `diesel_cli`.

I've noticed this issue: https://github.com/diesel-rs/diesel/issues/286. But how can make sure pg_config is on the path, or libpq is in /usr/local/include or some other path that ld can see.
I'm using ubuntu 15.10, postgresql and sqlite3 have been installed. libpq and libsqlite3 are in path "/usr/lib/x86_64-linux-gnu".
My "/etc/ld.so.conf"are:

include /etc/ld.so.conf.d/*.conf

My "/etc/ld.so.conf.d/x86_64-linux-gnu.conf" are:

# Multiarch support
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu

So, how can i solve this problem, thank you!

Most helpful comment

I just stucked into the same error. I had already installed libpq5 and libmysqlclient20 on my pc. Solution was sudo apt install libpq-dev libmysqlclient-dev and everything compiled successfully with cargo install diesel_cli without extra parameters

All 17 comments

Most of the time pg_config will be installed to /usr/bin/pg_config, which is almost definitely on your $PATH. To try and find it on your machine, you could run sudo updatedb && sudo locate pg_config, which will list the absolute paths of files that match. If it's not anywhere, that means you're missing libpq-dev, and will need to install that.

If you're not looking for sqlite support, you should install diesel_cli with

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

which won't compile the sqlite libs. If you do want sqlite support, you'll also need to install sqlite on your machine.

@mcasper pg_config is installed to /usr/bin/pg_config in my machine. And it is on my $PATH. But the error still exists.

fuying@fuying-linux:~$ echo $PATH
/home/fuying/.multirust/toolchains/nightly/cargo/bin:/home/fuying/.multirust/toolchains/nightly/bin:/home/fuying/.cargo/bin:/usr/lib/postgresql/9.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

Do you also have libpq installed?

I had the same issue. I found that my postgresql lib was under /usr/pgsql-9.3/lib/. So i symlink the libpq.so.5 to /usr/lib/libpq.so

sudo ln -s /usr/pgsql-9.3/lib/libpq.so.5 /usr/lib/libpq.so

Then it compiled just fine. I'm on Fedora and have postgresql93-libs installed.

Hope that helps.

@sgrif Yes, I have installed libpq. I used the method of @mann-ed . And it works. Thanks for your help

@mann-ed Use your method, and it works, Thanks for your help

I do want to see if we can improve this scenario, as it's a common stumbling point. Can you tell me what the output of pg_config --libdir is when the symlink isn't there? We may need to ask pg_config for the specific file to link against or something.

@sgrif
On my computer, 'pg_config' is not installed:

fuying@fuying-linux:~$ pg_config --libdir
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.

@fuyingfuying In https://github.com/diesel-rs/diesel/issues/321#issuecomment-218053859 you said it was... Anyway that looks like the root of the problem here, and the message given is definitely the correct solution. I'll see if I can improve the error message in pq-sys when pg_config isn't installed

@sgrif
ok

I just stucked into the same error. I had already installed libpq5 and libmysqlclient20 on my pc. Solution was sudo apt install libpq-dev libmysqlclient-dev and everything compiled successfully with cargo install diesel_cli without extra parameters

@mann-ed method worked for me in linux mint.
thank you very much!!!

Just went through this problem too, it would be useful to document which packages need to be installed in order for the installation to succeed, per OS/distro.
Apart from that great lib ! it hits the sweet spot between sql by hand and full blown ORM magic.

@nmrshll I think this belongs to the getting started guide on our homepage. Feel free to submit a PR there, that mentions that the postgres variant needs libpq and the mysql variant libmysqlclient. I would say that we cannot list the package names for all distros out there, therefore we should just say that you need those libraries.

Solved by this:

yum install postgresql-devel
cargo install diesel_cli --no-default-features --features postgres

I had the same issue. I found that my postgresql lib was under /usr/pgsql-9.3/lib/. So i symlink the libpq.so.5 to /usr/lib/libpq.so

sudo ln -s /usr/pgsql-9.3/lib/libpq.so.5 /usr/lib/libpq.so

Then it compiled just fine. I'm on Fedora and have postgresql93-libs installed.

Hope that helps.

Thank you, this worked for me. Cheers

Hey folks, I get that this issue probably shows up high on the search results for some term, but a closed issue from 2016 is not the right place to ask for support. If you believe there is a bug in Diesel CLI you should open a new issue, and if you need support you should ask in our gitter channel.

Was this page helpful?
0 / 5 - 0 ratings