diesel: failed to compile `diesel_cli v0.6.1`./usr/bin/ld: cannot find -lpq, cannot find -lsqlite3
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:

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!
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (6 by maintainers)
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-devand everything compiled successfully withcargo install diesel_cliwithout extra parametersMost of the time
pg_configwill be installed to/usr/bin/pg_config, which is almost definitely on your $PATH. To try and find it on your machine, you could runsudo updatedb && sudo locate pg_config, which will list the absolute paths of files that match. If it’s not anywhere, that means you’re missinglibpq-dev, and will need to install that.If you’re not looking for sqlite support, you should install diesel_cli with
which won’t compile the sqlite libs. If you do want sqlite support, you’ll also need to install sqlite on your machine.
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.
@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.
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.
@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