I am attempting to run and building my rust code, I built the sample rust project using cargo new sampleProject
, and then attempted to run it using cargo run and cargo build, both of which are failing, I have looked at internet solutions and to no avail, yesterday was my first time writing rust code.
I am using a macbook air m2 with arm64-apple-darwin-architecture, I have tested to make sure if my gcc compiler and cc --version is working, I have also tested my c code to make sure it's compiling, since I am assuming rust is linked with c compiler, I have installed rust from the official website, tried using xcode-select --install after removing the xcode tools as well but that also didn't fix the problem for me.
content within zshrc file, I attempted to comment them out to see if my environmental variables were somehow messed up or not:
# export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"
# export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"
# export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"
# export CC="$(brew --prefix gcc@13)/bin/gcc-13"
# export CXX="$(brew --prefix gcc@13)/bin/g++-13"
# export clangcpp_new="/opt/homebrew/opt/llvm/bin/clang++"
# export clangc_new="/opt/homebrew/opt/llvm/bin/clang"
# export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
# export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
# export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
# export gcc="/opt/homebrew/opt/gcc@12/bin/gcc-12"
# export gpp="/opt/homebrew/opt/gcc@12/bin/g++-12"
# export sdkmanager="/Users/ayandas/Library/Android/sdk"
The following is my cargo.toml file content:
[package]
name = "sampleProject"
version = "0.1.0"
edition = "2021"
[dependencies]
Additionally, the following is my src/main.rs:
fn main() {
println!("Hello, world!");
}
The following is the error message I am receiving:
ayandas@Mac sampleProject % cargo run
Compiling sampleProject v0.1.0 (/Users/ayandas/Desktop/bots_and_extensions/UDP_Reliable_Data_Transfer/sampleProject)
error: linking with `cc` failed: exit status: 1
|
= note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET -u XROS_DEPLOYMENT_TARGET LC_ALL="C" PATH="/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/ayandas/.pyenv/versions/anaconda3-2023.09-0/bin:/Users/ayandas/.pyenv/versions/anaconda3-2023.09-0/condabin:/opt/homebrew/opt/llvm/bin:/opt/homebrew/opt/openjdk@17/bin:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/opt/openjdk/bin:/Users/ayandas/.pyenv/versions/anaconda3-2023.09-0/bin:/Users/ayandas/.pyenv/versions/anaconda3-2023.09-0/condabin:/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:/Users/ayandas/.cargo/bin:/Users/ayandas/.pyenv/versions/anaconda3-2023.09-0/bin:/Users/ayandas/.pyenv/versions/anaconda3-2023.09-0/condabin:/opt/homebrew/opt/llvm/bin:/opt/homebrew/opt/openjdk@17/bin:/opt/homebrew/opt/openjdk/bin:/Users/ayandas/Library/Application Support/JetBrains/Toolbox/scripts:/Users/ayandas/Library/Application Support/JetBrains/Toolbox/scripts" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "arm64" "/var/folders/mv/0w9zk5p92rbdv1s56d65qh_r0000gn/T/rustcm2wz9Z/symbols.o" "/Users/ayandas/Desktop/bots_and_extensions/UDP_Reliable_Data_Transfer/sampleProject/target/debug/deps/sampleProject-b9f992f80c2a1d73.0alt8ob0vwu7e1k7tft4t6xhy.rcgu.o" "/Users/ayandas/Desktop/bots_and_extensions/UDP_Reliable_Data_Transfer/sampleProject/target/debug/deps/sampleProject-b9f992f80c2a1d73.0ctv30qf23gc5ye7dj8l051st.rcgu.o" "/Users/ayandas/Desktop/bots_and_extensions/UDP_Reliable_Data_Transfer/sampleProject/target/debug/deps/sampleProject-b9f992f80c2a1d73.4q1fz5vtitkx1q87pnp60v5wh.rcgu.o" "/Users/ayandas/Desktop/bots_and_extensions/UDP_Reliable_Data_Transfer/sampleProject/target/debug/deps/sampleProject-b9f992f80c2a1d73.8fo7ok66weeljhaffzfgj7e1x.rcgu.o" "/Users/ayandas/Desktop/bots_and_extensions/UDP_Reliable_Data_Transfer/sampleProject/target/debug/deps/sampleProject-b9f992f80c2a1d73.dsbgd78nxncoe9roh4zxr3siu.rcgu.o" "/Users/ayandas/Desktop/bots_and_extensions/UDP_Reliable_Data_Transfer/sampleProject/target/debug/deps/sampleProject-b9f992f80c2a1d73.eqemxn7e0a18mot7mu7ukaa2k.rcgu.o" "/Users/ayandas/Desktop/bots_and_extensions/UDP_Reliable_Data_Transfer/sampleProject/target/debug/deps/sampleProject-b9f992f80c2a1d73.8k9c854dudre7iybt5kshuth9.rcgu.o" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd-0b4a354a5d882f18.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-00e89274fccf37d9.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libobject-16cb3fa9562569e5.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-726032628236814d.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-3a2050392888e443.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgimli-22481e5f0a7ce87c.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-99efda3e7d60c7d0.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-97279fd1ed4043e6.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-14aec4517faeb95b.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-ce8f05ca22908841.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-45050aa8ac83ac5c.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libadler-3a0b6babb2efec9c.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunwind-41b79f23e35577db.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-7831295d10c91204.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liblibc-f86e480d5dcc309d.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liballoc-a7504b44dda8a2a3.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-589a9d977c5a484f.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-a17e2a568e77fc15.rlib" "/Users/ayandas/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-791901bf82ad4f12.rlib" "-lSystem" "-lc" "-lm" "-o" "/Users/ayandas/Desktop/bots_and_extensions/UDP_Reliable_Data_Transfer/sampleProject/target/debug/deps/sampleProject-b9f992f80c2a1d73" "-Wl,-dead_strip" "-nodefaultlibs"
= note: ld: warning: ignoring file '/usr/local/lib/libunwind.1.0.dylib': found architecture 'x86_64', required architecture 'arm64'
Undefined symbols for architecture arm64:
"__Unwind_Backtrace", referenced from:
_$LT$std..sys..backtrace..BacktraceLock..print..DisplayBacktrace$u20$as$u20$core..fmt..Display$GT$::fmt::habbf9c4f641febb1 in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
"__Unwind_DeleteException", referenced from:
___rust_panic_cleanup in libpanic_unwind-00e89274fccf37d9.rlib[3](panic_unwind-00e89274fccf37d9.panic_unwind.ea3026af965941fa-cgu.0.rcgu.o)
"__Unwind_GetDataRelBase", referenced from:
core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h184fa3c46de4de03 in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
std::sys::personality::gcc::find_eh_action::_$u7b$$u7b$closure$u7d$$u7d$::h9016764707eea70b in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
"__Unwind_GetIP", referenced from:
std::sys::backtrace::_print_fmt::_$u7b$$u7b$closure$u7d$$u7d$::h93a3e572f868b7e5 in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
std::sys::backtrace::_print_fmt::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::hfa3255d0d5665de5 in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
std::backtrace_rs::symbolize::gimli::resolve::h9bccc30f1d01026e in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
"__Unwind_GetIPInfo", referenced from:
_rust_eh_personality in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
"__Unwind_GetLanguageSpecificData", referenced from:
_rust_eh_personality in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
"__Unwind_GetRegionStart", referenced from:
_rust_eh_personality in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
"__Unwind_GetTextRelBase", referenced from:
core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::hedd8e747f837e7c9 in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
std::sys::personality::gcc::find_eh_action::_$u7b$$u7b$closure$u7d$$u7d$::h21c0c0abca010c25 in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
"__Unwind_RaiseException", referenced from:
___rust_start_panic in libpanic_unwind-00e89274fccf37d9.rlib[3](panic_unwind-00e89274fccf37d9.panic_unwind.ea3026af965941fa-cgu.0.rcgu.o)
"__Unwind_Resume", referenced from:
core::ops::function::FnOnce::call_once::h88ab541bd2b2b5f1 in sampleProject-b9f992f80c2a1d73.4q1fz5vtitkx1q87pnp60v5wh.rcgu.o
core::fmt::Write::write_char::h9373e5340b0b2cbc in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
core::fmt::Write::write_char::ha0b71a4765f50798 in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h3311feb78f89f46f in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
core::ptr::drop_in_place$LT$alloc..vec..Vec$LT$$LP$usize$C$std..backtrace_rs..symbolize..gimli..Mapping$RP$$GT$$GT$::hce47ddc093b7fbdd in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
core::ptr::drop_in_place$LT$addr2line..Context$LT$gimli..read..endian_slice..EndianSlice$LT$gimli..endianity..LittleEndian$GT$$GT$$GT$::h6edd28cbd41e721b in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
core::ptr::drop_in_place$LT$addr2line..ResUnit$LT$gimli..read..endian_slice..EndianSlice$LT$gimli..endianity..LittleEndian$GT$$GT$$GT$::h2d9205394c68f7a0 in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
...
"__Unwind_SetGR", referenced from:
_rust_eh_personality in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
_rust_eh_personality in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
"__Unwind_SetIP", referenced from:
_rust_eh_personality in libstd-0b4a354a5d882f18.rlib[3](std-0b4a354a5d882f18.std.d8d90c69e022292b-cgu.0.rcgu.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: could not compile sampleProject (bin "sampleProject") due to 1 previous error
The following is the output of my cc --version
ayandas@Mac sampleProject % cc --version
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin24.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
ayandas@Mac sampleProject %
NOTE: I have several gcc and g++ compilers installed because at some point my c++ compiler broke and I went through a rabbit hole to fix it, but since then, a clean reinstallation has fixed it and I can compile C++/C code fine using the default clang and gcc compilers and the custom ones that I have installed, I am assuming that is the root cause, but I have no idea how to fix something like this
Here are the following list of things that I have tried:
cargo new sampleProject
and run it with no added modificationsxocde-select --install
method.an update to this problem. After much struggle, I was able to determine an appropriate solution to this issue. It seems the default path to my C compiler is somehow not compatible with cargo, and I have to specify the path to my C linker, which I have multiple versions of. (Clang, GCC-12, GCC-13).
If I were to type in where gcc
, the output would be : /usr/bin/gcc
. Similarly, if I were to type in where clang
, the outputs would be the following (provided in list for easier readability):
/opt/homebrew/opt/llvm/bin/clang
/opt/homebrew/opt/llvm/bin/clang
/usr/local/bin/clang
/usr/bin/clang
As part of reference, the content of my ~/.zshrc
is the following:
export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"
export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"
export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"
export CustomCC="$(brew --prefix gcc@13)/bin/gcc-13"
export CXX="$(brew --prefix gcc@13)/bin/g++-13"
export clangcpp_new="/opt/homebrew/opt/llvm/bin/clang++"
export clangc_new="/opt/homebrew/opt/llvm/bin/clang"
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
export gcc_12="/opt/homebrew/opt/gcc@12/bin/gcc-12"
export gpp_12="/opt/homebrew/opt/gcc@12/bin/g++-12"
export sdkmanager="/Users/ayandas/Library/Android/sdk"
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
# export PATH="/usr/bin/cc:$PATH"
I have ran some tests to determine the paths that does work and the paths that doesn't work: (For Both GCC and clang based compiler)
RUSTFLAGS="-C linker=/opt/homebrew/opt/gcc@12/bin/gcc-12" cargo run
: passRUSTFLAGS="-C linker=/opt/homebrew/bin/gcc-13" cargo run
: passRUSTFLAGS="-C linker=/opt/homebrew/opt/llvm/bin/clang" cargo run
: passRUSTFLAGS="-C linker=/usr/bin/gcc" cargo run
: failRUSTFLAGS="-C linker=/usr/local/bin/clang" cargo run
: failRUSTFLAGS="-C linker=/usr/bin/clang
: failThe reference that helped me the most was the following: Github Discussion #1109
I hope this helps for anyone runs into a similar issue such as mine. You can install a difference version of gcc and llvm and determine their path using where gcc
and where clang
and test out the paths to see which works. (NOTE: You can install clang using brew install llvm
) if for some reason clang compiler paths are not working as intended within /usr/bin
section, as that was the issue with mine originally).