[SOLVED!] On FreeBSD 14.3 "ld: error" when trying to build and run "hello world" program

I was trying to run a small "hello world" program and received a few errors. This is one of them. I have a new Rust installation with Cargo on FreeBSD14.3

root@user-ghostbsd:/home/user/Downloads/memory # cargo run
Compiling proc-macro2 v1.0.105
Compiling quote v1.0.43
Compiling libm v0.2.15
Compiling libc v0.2.180
Compiling serde_core v1.0.228
Compiling portable-atomic v1.13.0
Compiling serde v1.0.228
Compiling rustix v1.1.3
error: linking with cc failed: exit status: 1
|
= note: "cc" "-m64" "/tmp/rustcYZEtLK/symbols.o" "<2 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/lib/rustlib/x86_64-unknown-freebsd/lib/{libstd-,libpanic_unwind-,libobject-,libmemchr-,libaddr2line-,libgimli-,libcfg_if-,librustc_demangle-,libstd_detect-,libhashbrown-,librustc_std_workspace_alloc-,libminiz_oxide-,libadler2-,libunwind-,liblibc-,librustc_std_workspace_core-,liballoc-,libcore-,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lexecinfo" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lrt" "-lutil" "-lexecinfo" "-lkvm" "-lmemstat" "-lkvm" "-lutil" "-lprocstat" "-lrt" "-ldevstat" "-L" "/tmp/rustcYZEtLK/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-o" "/home/user/Downloads/memory/target/debug/build/quote-ebcbd81c14b23f6f/build_script_build-ebcbd81c14b23f6f" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
= note: some arguments are omitted. use --verbose to show all linker arguments
= note: ld: error: cannot open Scrt1.o: No such file or directory
ld: error: cannot open crti.o: No such file or directory
ld: error: cannot open crtbeginS.o: No such file or directory
ld: error: unable to find library -lexecinfo
ld: error: unable to find library -lpthread
ld: error: unable to find library -lgcc_s
ld: error: unable to find library -lc
ld: error: unable to find library -lm
ld: error: unable to find library -lrt
ld: error: unable to find library -lpthread
ld: error: unable to find library -lrt
ld: error: unable to find library -lutil
ld: error: unable to find library -lexecinfo
ld: error: unable to find library -lkvm
ld: error: unable to find library -lmemstat
ld: error: unable to find library -lkvm
ld: error: unable to find library -lutil
ld: error: unable to find library -lprocstat
ld: error: unable to find library -lrt
ld: error: unable to find library -ldevstat
ld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
cc: error: linker command failed with exit code 1 (use -v to see invocation)

There a few more errors, but each is about the same as the one above. I am new to Rust and FreeBSD (coming from Ubuntu Linux). The only "ld" folder I found was: /compat/linux/dev/fd/152854/ld and it was empty except for three files that seemed to not have anything to do with the "unable to find library" errors. I have the GNU compiler collection, cargo, and the Rust language installed.

Any help with this is appreciated much. Thanks.

I think you need to install clang and/or llvm.

pkg install llvm
pkg install clang
1 Like

[SOLVED!] Thanks abj. I discovered that my version of FreeBSD (GhostBSD) required:

pkg install -g 'GhostBSD*dev'

to download and install the items you mentioned. I have another identical PC with the mainstream FreeBSD installation from the FreeBSD website that did not need anything and worked fine after the normal installation. I did the mainstream installation (no desktop) after I had posted here as a test. Rust commands worked fine on mainstream FreeBSD in the terminal. I used GhostBSD because it came with a desktop already installed. Then, on the mainstream FreeBSD PC, I used "desktop-installer" and installed a KDE Plasma desktop with ease. I found out about "desktop-installer" a little late, but it's nice to have two PCs with FreeBSD. Rust works now on both just fine.

Thanks for the reply!

1 Like

In the future, consider filing a [A-diagnostics] ticket to GitHub - rust-lang/rust: Empowering everyone to build reliable and efficient software. for our toolchain to detect that a linker error happened because of the user's system environment not having everything it should have (like llvm) and emit a better diagnostic. The easiest thing would be to look at the ld output and detect that unable to find library followed by something fundamental is present and add a note telling the user to check their package manager for llvm (even better would be to have enough confidence to not print out the current error and instead emit a more straightforward error).

I think that this case would already fall under Unreadable error messages on linking failure · Issue #46998 · rust-lang/rust · GitHub, but more targeted tickets helps with tracking progress by being able to close them.

ekuber: Thanks for the reply. I will look at this. Thanks!