Rust [SOLVED!] error: linking with cc failed: exit status: 1 (with simple 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.
Code:
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-[I],libpanic_unwind-[/I],libobject-[I],libmemchr-[/I],libaddr2line-[I],libgimli-[/I],libcfg_if-[I],librustc_demangle-[/I],libstd_detect-[I],libhashbrown-[/I],librustc_std_workspace_alloc-[I],libminiz_oxide-[/I],libadler2-[I],libunwind-[/I],liblibc-[I],librustc_std_workspace_core-[/I],liballoc-[I],libcore-[/I],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. 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.
 
Last edited by a moderator:
I typed these commands into a terminal and updated the packages.

pkg update -f
pkg upgrade

I typed this afterwards:
freebsd-version -kru

and received:
Code:
root@user-ghostbsd:/ # freebsd-version -kru
14.3-RELEASE-p7
14.3-RELEASE-p7
14.3-RELEASE-p7
root@user-ghostbsd:/ #
I followed the Google link you sent. The Google files are identical to mine. I followed the instructions and used both "cargo run" and in another terminal window "rustc" like in the directions. The error message was the same for both runs.
Code:
root@user-ghostbsd:/home/user/Documents/Rust/hello_world # cargo build
   Compiling hello_world v0.1.0 (/home/user/Documents/Rust/hello_world)
error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" "-m64" "/tmp/rustcUXAW11/symbols.o" "<7 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/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/rustcUXAW11/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-o" "/home/user/Documents/Rust/hello_world/target/debug/deps/hello_world-209ce5c2dcd04bd0" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find Scrt1.o: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find crti.o: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find crtbeginS.o: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lexecinfo: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lpthread: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lgcc_s: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lc: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lm: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lrt: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lpthread: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lrt: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lutil: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lexecinfo: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lkvm: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lmemstat: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lkvm: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lutil: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lprocstat: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -lrt: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find -ldevstat: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find crtendS.o: No such file or directory
          /usr/local/bin/x86_64-unknown-freebsd14.3-ld: cannot find crtn.o: No such file or directory
          cc: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: could not compile `hello_world` (bin "hello_world") due to 1 previous error
root@user-ghostbsd:/home/user/Documents/Rust/hello_world #
I checked into that directory in the error message:
Code:
root@user-ghostbsd:/usr/local/bin # cd x86_64-unknown-freebsd14.3-ld
cd: x86_64-unknown-freebsd14.3-ld: Not a directory
root@user-ghostbsd:/usr/local/bin #
It may not mean anything, but this is my path:
Code:
root@user-ghostbsd:/ # echo $PATH
/home/user/.cargo/bin:/usr/local/gnat12/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/user/bin
root@user-ghostbsd:/ #
I'm still reading about this linking error and have not found anything yet. I have "GhostBSD" since it comes with a desktop. I tried for days to get a desktop on a mainstream version of FreeBSD, but the builds kept failing and I followed the manual. The Git "desktop-installer" did not work either. I'll be updating my FreeBSD version to 15 on the 16th of January when it comes available for GhostBSD. There is supposed to be a well funded FreeBSD laptop project that might make things easier to install, but it will take time for that to get completed.

Thanks for your time with this.
 
Last edited by a moderator:
I have a spare PC and installed FreeBSD 15 on it. This PC and the one with GhostBSD are both HP t740s that have the same CPU, RAM, and SSD. I installed Rust in the FreeBSD 15 shell and used "cargo" to create the files including the .toml file. I ran the main.rs file with cargo and received the "Hello World!" message in the shell. It all works fine. I did a full install with the FreeBSD system. Now, I have to figure out how to get a working desktop on it. Maybe with FreeBSD 15 I will have better luck.
 
unitrunker: I tried desktop-installer before and it did not work for me, BUT I just tried it again on a fresh install of FreeBSD 15 from the FreeBSD website and it worked! In case anyone tries this, you run desktop-installer twice. The second time you run it is after a reboot. I am coming from GNOME on Debian Linux, but saw alot of positives about KDE Plasma. I chose this. There were alot of files loading and installed. I did not try the other desktops in the desktop-install script. KDE was a long install and I went to get a cup of coffee. After so many days off and on with trying to install a desktop from, I think, every blog and article, I was shocked that desktop-installer worked. Now I have a desktop and Rust going well. I'll be very busy exploring this new desktop on my HP t740 Thin Client. "desktop-installer" is a polished work of art! Thanks "desktop-installer" for making me happy. :)
 
A command specific to GhostBSD will install the missing files. I received this from someone at the GhostBSD forum. This fixed the problem and Rust is fine on GhostBSD, too. The command is below:

pkg install -g 'GhostBSD*dev'

Thanks again.
 
Back
Top