Facing linking issue while running simple "Hello World" program

While running rustc main.rs
Facing the below linking error
rustc main.rs
error: linking with cc failed: exit status: 1
|
= note: LC_ALL="C" PATH="/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/usr/local/bin/vegaappsdktools:/Users/uckumar/.nvm/versions/node/v12.22.12/bin:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/opt/homebrew/opt/ruby/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/uckumar/.cargo/bin:/Users/uckumar/.toolbox/bin" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "arm64" "/var/folders/sf/20sss29x58s624lz6kyqt2380000gr/T/rustcGjqVdU/symbols.o" "main.main.b620efc257d42d9c-cgu.0.rcgu.o" "main.52fsdrpxr24z69pc.rcgu.o" "-L" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd-3d2f8249df972181.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-71f458d6ad9754d3.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libobject-80ca13cc75b9f1f8.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-f61e6e34bb7e3d2c.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-0e0bd047a1477984.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgimli-2e16542b46c8c2c1.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-715d432050230d26.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-07347eb75450f6dc.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-9def065c9187ef49.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-a77178b509a93e9e.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-e52109799d3633b0.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libadler-71de85e71b396682.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunwind-9d1db45aded26b54.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-dc8bc139addbc9a1.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liblibc-43ed22d1545fab87.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liballoc-dfb3f449d0391fb9.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-921be82af751e98a.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-ad57bf2066878332.rlib" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-7bc3106ba9bea571.rlib" "-lSystem" "-lc" "-lm" "-L" "/Users/uckumar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "-o" "main" "-Wl,-dead_strip" "-nodefaultlibs"
= note: ld: library not found for -lSystem
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error

Any help would be appreciated!

Using Apple M1 Pro
macOS ventura 13.6

You need to install a C toolchain. Apple misleadingly calls that the "Xcode Command-Line Tools". (It has exactly nothing to do with Xcode, so you won't need to install Xcode for using it.)

It is already installed, as you can see in the output of PATH. Also, it is clang which is reporting the linker error.
He is also using Homebrew, which doesn't work without them.

@uckumar
There is no "real" libSystem any more (since Big Sur) on MacOS, but the linker is supposed to know about that. Which version of clang (Command Line Tools) are you using, what does clang --version say?

1 Like

Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

This Wikipedia page says that's XCode 14.2.

You could try updating (to 14.3.1 or 15) or reinstalling the command line tools, maybe that helps.

That works for me (rustc 1.73.0, XCode (Tools) 15):

% cat main.rs                    
fn main() {
    println!("Hi!")
}

% rustc main.rs --print link-args
LC_ALL="C"
PATH="/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/opt/homebrew/opt/curl/bin:/Users/roland/.opam/5.0.0/bin:/Users/roland/.elan/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Library/TeX/texbin:/usr/local/share/dotnet:~/.dotnet/tools:/opt/homebrew/opt/curl/bin:/Users/roland/.opam/5.0.0/bin:/Users/roland/.elan/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/roland/.wasmedge/bin:/Users/roland/.cargo/bin:/Users/roland/.local/bin:/Users/roland/.ghcup/bin:/Users/roland/.pack/bin:/Users/roland/.ghcup/bin:/Users/roland/.pack/bin" 
VSLANG="1033"
ZERO_AR_DATE="1" 
"cc" "-arch" "arm64" "/var/folders/07/f6y7bm0x7n72vhtwd596514h0000gn/T/rustcxT0q3X/symbols.o" "main.main.b620efc257d42d9c-cgu.0.rcgu.o" "main.52fsdrpxr24z69pc.rcgu.o" "-L" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd-3d2f8249df972181.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-71f458d6ad9754d3.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libobject-80ca13cc75b9f1f8.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-f61e6e34bb7e3d2c.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-0e0bd047a1477984.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgimli-2e16542b46c8c2c1.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-715d432050230d26.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-07347eb75450f6dc.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-9def065c9187ef49.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-a77178b509a93e9e.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-e52109799d3633b0.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libadler-71de85e71b396682.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunwind-9d1db45aded26b54.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-dc8bc139addbc9a1.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liblibc-43ed22d1545fab87.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liballoc-dfb3f449d0391fb9.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-921be82af751e98a.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-ad57bf2066878332.rlib" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-7bc3106ba9bea571.rlib" "-lSystem" "-lc" "-lm" "-L" "/Users/roland/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "-o" "main" "-Wl,-dead_strip" "-nodefaultlibs"

I do not see any additional library paths (after -L), it's the same as your command line (the two library paths are actually the same, so that's redundant).

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.