Error: linking with `cc` failed: exit status: 1 -

I'm trying run the first hello world using rust main.rs in mac m1 but unfortunately I'm getting this error.

error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-arch" "arm64" "/var/folders/jp/mw5xl5hj5r7d729sjp379tzc0000gn/T/rustcoKFTIE/symbols.o" "main.main.86b4c380-cgu.0.rcgu.o" "main.main.86b4c380-cgu.1.rcgu.o" "main.main.86b4c380-cgu.2.rcgu.o" "main.main.86b4c380-cgu.3.rcgu.o" "main.main.86b4c380-cgu.4.rcgu.o" "main.main.86b4c380-cgu.5.rcgu.o" "main.3b77437zuaj579vq.rcgu.o" "-L" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd-b98ae94127188ce9.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-3750fc08257cf4a1.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libobject-1932a6859587976a.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-5eb9437182bba25e.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-159667f06d85af23.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgimli-fe56ccf961546e3d.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-ff3530f9f8d34aa1.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-b3f57baaaa09d1c8.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-ad6ad023debadb7b.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-3e92780fe433cd7d.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-20659468df103b74.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libadler-51cc45c540a3acd1.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-c3b8a66800f40b38.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunwind-1334679efb5b30d9.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-06512a06152474f4.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liblibc-c20be46cbe7db35f.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liballoc-f4ececa123832abf.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-61d379856dcb6dc6.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-e48a983765cd78b4.rlib" "/Users/luanacajaiba/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-635ac2664b5ede2a.rlib" "-lSystem" "-lc" "-lm" "-L" "/Users/luanacajaiba/.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

these are the versions:

rustc 1.66.1 
cargo 1.66.1 

I already tried the commands:

softwareupdate --install -a
xcode-select --install
sudo xcode-select --reset

I already reinstalled the Xcode command line tools and nothing.

1 Like

You have rustup for x86_64, and it's confused about your platform, because it is running under Rosetta emulation.

Run rustup self uninstall and install Rust again.

2 Likes

I'm currently facing the exact same issue, I have done the same steps as @LuanaCajaiba and freshly installed Rust as recommended by @kornel, but the issue persists:

  = note: ld: library not found for -lmylib
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

Using latest verion of aarch64-apple-darwin on Mac Ventura 13.1

When the linker complains about a specific -l flag, without errors about invalid architecture or missing x86_64 sections of fat binaries, this is a different problem, unrelated to rustup.

In your case this is probably the most common issue of not having mylib installed, or having mylib installed without mylib-devel package, or having it fully installed, but not having -L search path set to the actual location where mylib is, or trying to link a static version of mylib when only a dynamic one is available or vice-versa. You could also be lacking pkg-config tool, or the -sys crate you've used could be buggy. There are lots of reasons why a C library could fail to link.

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.