Linker fails to find xcb on FreeBSD

Trying to compile amp and the linker is failing:

error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.0.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.1.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.10.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.11.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.12.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.13.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.14.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.15.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.2.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.3.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.4.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.5.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.6.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.7.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.8.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.amp.8912b33b-cgu.9.rcgu.o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37.xjuxpr6w029wdy3.rcgu.o" "-Wl,--as-needed" "-L" "/usr/home/nathan/src/amp/target/release/deps" "-L" "/usr/home/nathan/src/amp/target/release/build/backtrace-sys-1c0785764cf34bb4/out" "-L" "/usr/home/nathan/src/amp/target/release/build/libgit2-sys-25d167adaa7bec30/out/build" "-L" "/usr/home/nathan/src/amp/target/release/build/miniz-sys-48fb24b85e16c093/out" "-L" "/usr/home/nathan/src/amp/target/release/build/onig_sys-3aa7d167b11be4a7/out/build" "-L" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib" "-Wl,-Bstatic" "/usr/home/nathan/src/amp/target/release/deps/libamp-37cd5eaa667f4684.rlib" "/usr/home/nathan/src/amp/target/release/deps/libtermion-b56918be64085dd8.rlib" "/usr/home/nathan/src/amp/target/release/deps/liberror_chain-097838bcac21eecd.rlib" "/usr/home/nathan/src/amp/target/release/deps/libsmallvec-f6497abfdecf5581.rlib" "/usr/home/nathan/src/amp/target/release/deps/libclipboard-3c7d02e7aaff3845.rlib" "/usr/home/nathan/src/amp/target/release/deps/libx11_clipboard-d57081455584aa01.rlib" "/usr/home/nathan/src/amp/target/release/deps/libxcb-a5344cb0b2262639.rlib" "/usr/home/nathan/src/amp/target/release/deps/liberror_chain-d3e0544891f4e758.rlib" "/usr/home/nathan/src/amp/target/release/deps/libsignal_hook-e493919bd4cc44d1.rlib" "/usr/home/nathan/src/amp/target/release/deps/libsignal_hook_registry-45b93bae84578dbe.rlib" "/usr/home/nathan/src/amp/target/release/deps/libarc_swap-0f4a3e0f4426f948.rlib" "/usr/home/nathan/src/amp/target/release/deps/libmio_uds-0ce8134e9c0a0d6c.rlib" "/usr/home/nathan/src/amp/target/release/deps/libscribe-601f8d290c3405c2.rlib" "/usr/home/nathan/src/amp/target/release/deps/liberror_chain-d459c31e890f2777.rlib" "/usr/home/nathan/src/amp/target/release/deps/libbacktrace-ae53b5f813e5c60e.rlib" "/usr/home/nathan/src/amp/target/release/deps/libbacktrace_sys-eb30cf02e9f7716f.rlib" "/usr/home/nathan/src/amp/target/release/deps/librustc_demangle-1109c656885a8d59.rlib" "/usr/home/nathan/src/amp/target/release/deps/libunicode_segmentation-c8281707e32455c4.rlib" "/usr/home/nathan/src/amp/target/release/deps/libsyntect-b94b75bfd43bc101.rlib" "/usr/home/nathan/src/amp/target/release/deps/libserde_json-fce871ede635dc36.rlib" "/usr/home/nathan/src/amp/target/release/deps/libitoa-c70247b59362cf76.rlib" "/usr/home/nathan/src/amp/target/release/deps/libdtoa-cbb031a7cdf7e7a7.rlib" "/usr/home/nathan/src/amp/target/release/deps/libfnv-448d49d096fd0bf4.rlib" "/usr/home/nathan/src/amp/target/release/deps/libflate2-378d05c31b298892.rlib" "/usr/home/nathan/src/amp/target/release/deps/libminiz_sys-6685371b6612391f.rlib" "/usr/home/nathan/src/amp/target/release/deps/libbincode-5b8e26f20f16a3a7.rlib" "/usr/home/nathan/src/amp/target/release/deps/libplist-b5c144971f368199.rlib" "/usr/home/nathan/src/amp/target/release/deps/libserde-405da76ad751098c.rlib" "/usr/home/nathan/src/amp/target/release/deps/libxml-df74cb7b6d0af6c7.rlib" "/usr/home/nathan/src/amp/target/release/deps/libchrono-75369bce8d2f1d8b.rlib" "/usr/home/nathan/src/amp/target/release/deps/libnum_integer-e97a2879b00e1c4b.rlib" "/usr/home/nathan/src/amp/target/release/deps/libnum_traits-9b9de9a8b76e5ef4.rlib" "/usr/home/nathan/src/amp/target/release/deps/libtime-135631b201b15163.rlib" "/usr/home/nathan/src/amp/target/release/deps/libbase64-d48e860adfa0a386.rlib" "/usr/home/nathan/src/amp/target/release/deps/libsafemem-ad3aebf9918a550a.rlib" "/usr/home/nathan/src/amp/target/release/deps/libbyteorder-52454a6420105a58.rlib" "/usr/home/nathan/src/amp/target/release/deps/libregex_syntax-660d2fd6ed8b62ec.rlib" "/usr/home/nathan/src/amp/target/release/deps/libonig-4020e859dcba32a5.rlib" "/usr/home/nathan/src/amp/target/release/deps/libonig_sys-6254043b0a30e193.rlib" "/usr/home/nathan/src/amp/target/release/deps/liblazy_static-a26040fd29cd262b.rlib" "/usr/home/nathan/src/amp/target/release/deps/libyaml_rust-c0c229cee87de8f2.rlib" "/usr/home/nathan/src/amp/target/release/deps/liblinked_hash_map-f34d724cb09ce0e3.rlib" "/usr/home/nathan/src/amp/target/release/deps/libregex-a26e71b2fc99a5b1.rlib" "/usr/home/nathan/src/amp/target/release/deps/libutf8_ranges-ec6ec1d25c95549f.rlib" "/usr/home/nathan/src/amp/target/release/deps/libregex_syntax-9973e95549a2158c.rlib" "/usr/home/nathan/src/amp/target/release/deps/libthread_local-ab70d10a5ef8de72.rlib" "/usr/home/nathan/src/amp/target/release/deps/libthread_id-751ff278873f8be1.rlib" "/usr/home/nathan/src/amp/target/release/deps/libaho_corasick-fa927b4dfc4ced9f.rlib" "/usr/home/nathan/src/amp/target/release/deps/libmemchr-1f06d34a6f0d32b8.rlib" "/usr/home/nathan/src/amp/target/release/deps/libmio-5c42271a93b5922c.rlib" "/usr/home/nathan/src/amp/target/release/deps/libslab-1108758039f3286a.rlib" "/usr/home/nathan/src/amp/target/release/deps/libiovec-291a7a70cdbcb60c.rlib" "/usr/home/nathan/src/amp/target/release/deps/libnet2-59bbb8cb5525b5e9.rlib" "/usr/home/nathan/src/amp/target/release/deps/liblazycell-c087e30923f75037.rlib" "/usr/home/nathan/src/amp/target/release/deps/libluthor-f55b6817ab220c6c.rlib" "/usr/home/nathan/src/amp/target/release/deps/libgit2-1eda27089de73c18.rlib" "/usr/home/nathan/src/amp/target/release/deps/liburl-91441d23be64b3b9.rlib" "/usr/home/nathan/src/amp/target/release/deps/libpercent_encoding-19561d157a8778ca.rlib" "/usr/home/nathan/src/amp/target/release/deps/libidna-b79db2a5647016fc.rlib" "/usr/home/nathan/src/amp/target/release/deps/libunicode_normalization-21dde24c4e2fcb30.rlib" "/usr/home/nathan/src/amp/target/release/deps/libunicode_bidi-03580bb9be801bc9.rlib" "/usr/home/nathan/src/amp/target/release/deps/libmatches-b07acea7b0af07ae.rlib" "/usr/home/nathan/src/amp/target/release/deps/liblog-85f23b0cba13a071.rlib" "/usr/home/nathan/src/amp/target/release/deps/libcfg_if-a5a227cccba7eaa3.rlib" "/usr/home/nathan/src/amp/target/release/deps/liblibgit2_sys-f1466aebf64363ce.rlib" "/usr/home/nathan/src/amp/target/release/deps/liblibz_sys-69d863715caca31b.rlib" "/usr/home/nathan/src/amp/target/release/deps/liblibc-11a07e1f19adc682.rlib" "/usr/home/nathan/src/amp/target/release/deps/libbitflags-f284577dbb913a13.rlib" "/usr/home/nathan/src/amp/target/release/deps/libbloodhound-9d607408ef33be2e.rlib" "/usr/home/nathan/src/amp/target/release/deps/libwalkdir-9e68a44ea30f792b.rlib" "/usr/home/nathan/src/amp/target/release/deps/libsame_file-bb9c2b40030ef40a.rlib" "/usr/home/nathan/src/amp/target/release/deps/libglob-f46892f7c76ef57d.rlib" "/usr/home/nathan/src/amp/target/release/deps/libfragment-d37040be790f676e.rlib" "/usr/home/nathan/src/amp/target/release/deps/libapp_dirs-f2ca830ff805a2ff.rlib" "/usr/home/nathan/src/amp/target/release/deps/libxdg-be7376febd9533eb.rlib" "-Wl,--start-group" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libstd-b4599c8c8b9caf68.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libpanic_unwind-39543ccc0ce46f60.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libminiz_oxide-01deaed31589600a.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libadler-5d8406ad04a87e29.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libobject-4aaeeedca432fdb9.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libmemchr-a3b62cf9e65f7389.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libaddr2line-1c8bdec4de96bcf5.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libgimli-2a483892add640f4.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libstd_detect-e33415f2b8594fab.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_demangle-24cf3ac7c79ab4da.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libhashbrown-1d207a87236d676d.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_std_workspace_alloc-1151614ba2c1d11b.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libunwind-96836c877beb38d1.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libcfg_if-5e0745ff162b8ff2.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/liblibc-b138aa5636b1984a.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/liballoc-97ae5222bd9d13c8.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_std_workspace_core-174ebf435975ffef.rlib" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libcore-ce9110d7ae9a5977.rlib" "-Wl,--end-group" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libcompiler_builtins-1b2fc8d274c31127.rlib" "-Wl,-Bdynamic" "-lxcb" "-lz" "-lutil" "-lexecinfo" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lrt" "-lutil" "-lexecinfo" "-lkvm" "-lutil" "-lprocstat" "-lrt" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/usr/home/nathan/.rustup/toolchains/nightly-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib" "-o" "/usr/home/nathan/src/amp/target/release/deps/amp-40d0a058d4c93a37" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-Wl,-O1" "-nodefaultlibs"
  = note: ld: error: unable to find library -lxcb
          cc: error: linker command failed with exit code 1 (use -v to see invocation)

I have libxcb at /usr/local/lib/libxcb.so. Can I pass linker parameters somehow through cargo?

Why do you have it in /usr/local/lib instead of /usr/lib? If you install the libxcb-dev package it should end up in /usr/lib. Either way I think you can set RUSTFLAGS to -L native=/usr/local/lib.

This may not be relevant to your post but I'm on GhostBSD and getting a lot of "...libraries not supported on your platform,yet." for Rust.That's a shame.

It’s a historical freebsd decision:
https://wiki.freebsd.org/WarnerLosh/UsrLocal

CMake just passes /usr/local/include and /usr/local/lib to the compiler and linker and avoids this headache. Cargo could probably do something similar.

/usr/local is the prefix that FreeBSD installs packages, always has been. FreeBSD is not Linux :slight_smile:

Thank you for the answer, though. I'll try that later.

Would be nice if it did.

Why doesn't freebsd's gcc driver do this? The gcc driver is responsible for making sure that the library path includes system libraries when invoking the linker. For example for me on linux the gcc driver invokes the linker as

COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'foo' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/10/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/10/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper -plugin-opt=-fresolution=/tmp/ccybAU2V.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -o foo /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/10/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/10 -L/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/10/../../.. -v /tmp/ccZzqegW.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/10/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o

As you can see it explicitly lists every possible location installed libraries could potentially be found. Why doesn't freebsd list /usr/local/lib here?

If anything it should go into the freebsd target specifications of rustc. Cargo barely has any platform specific knowledge. Even platform specific executable/library filename prefixes/suffixes are requested from rustc.

That did work, thank you very much.

Very informative. I hadn't realized that the system compiler had a different search path than those installed via ports. I imagine there's something in the ports tree Makefiles that's setting up their environment to get around that, when they could just build the system compiler with /usr/local in the search path since that's the canonical place to install third party packages. To me, that makes it more of a FreeBSD issue than a Rust issue, but it would still be nice if Rust provided the workaround so that it "just works" on FreeBSD.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.