Can't get hello-world to compile

Hi all, I installed rust and cargo as described on the website and created a new hello world app, however when I try to build or run it, I get the following error.

Ubuntu 22.10
rustc 1.68.2 (9eb3afe9e 2023-03-27)
cargo 1.68.2 (6feb7c9cf 2023-03-26)

❯ cargo build
   Compiling hello-rust v0.1.0 (/home/al/Git/rust-test/hello-rust)
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/al/bin:/usr/local/bin:/home/al/.local/bin:/home/al/.cargo/bin:/home/al/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/al/.dotnet/tools" VSLANG="1033" "cc" "-m64" "/tmp/rustckAWfPl/symbols.o" "/home/al/Git/rust-test/hello-rust/target/debug/deps/hello_rust-546d21950693fedc.163ie6xkwzbxwzqa.rcgu.o" "/home/al/Git/rust-test/hello-rust/target/debug/deps/hello_rust-546d21950693fedc.1d24xy3wena2l0ak.rcgu.o" "/home/al/Git/rust-test/hello-rust/target/debug/deps/hello_rust-546d21950693fedc.2id33r8bwp47xq4v.rcgu.o" "/home/al/Git/rust-test/hello-rust/target/debug/deps/hello_rust-546d21950693fedc.2q4ktwm62lafavnj.rcgu.o" "/home/al/Git/rust-test/hello-rust/target/debug/deps/hello_rust-546d21950693fedc.4wv56cqy5ezn5vew.rcgu.o" "/home/al/Git/rust-test/hello-rust/target/debug/deps/hello_rust-546d21950693fedc.kbw1tkj3rwq5a62.rcgu.o" "/home
/al/Git/rust-test/hello-rust/target/debug/deps/hello_rust-546d21950693fedc.2vd78vi0u3etd0l7.rcgu.o" "-Wl,--as-needed" "-L" "/home/al/Git/rust-test/hello-rust/target/debug/deps" "-L" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-bc6b80525d6b1f3b.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-dbb416fff97e9855.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-af60be54961a030f.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-1303bc5098cb2f44.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-96ca4807f9d03fdf.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-03b108942351d49a.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-b348df34b7d8ac11.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-26a06d9c5ec29d3a.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-b5295fdab67e4cf6.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-b257ed099e7f67d0.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-c27b5dca54e295d8.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-f6c8245d52afa66d.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-642c68f15c02cc52.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-eecd84150c4ad967.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-123ffa13a38501db.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-2177aff67f4e9999.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-2298a66e03bd0fd2.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-f3c3b25345711552.rlib" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-10f041ff25bad5f3.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/al/Git/rust-test/hello-rust/target/debug/deps/hello_rust-546d21950693fedc" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: /usr/bin/ld: /home/al/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-bc6b80525d6b1f3b.rlib(std-bc6b80525d6b1f3b.std.3431a86c-cgu.0.rcgu.o): undefined reference to symbol '__tls_get_addr@@GLIBC_2.3'
          /usr/bin/ld: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2: error adding symbols: DSO missing from command line
          collect2: error: ld returned 1 exit status
          
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `hello-rust` due to previous error

Looks like some problem when linking.
I'm only occasionally using Ubuntu, but my first thing to check would be if you've installed the "build-essentials" package using your package manager? And if it isn't installed, install it.

1 Like
sudo apt update
sudo apt install build-essential
rustup update

Linker can't find __tls_get_addr@@GLIBC_2.3. Make sure your native lib path is correct. LIBRARY_PATH=/usr/lib/x86_64-linux-gnu cargo build.

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.