1. 問題描述
執(zhí)行cargo命令:
RUST_LOG=info cargo run --example demo --quiet
錯誤如下:
error: linking with `cc` failed: exit status: 1
|
= note: LC_ALL="C" PATH="......."
= note: ld: in /.../my_project/target/debug/deps/libcrypto-d7fa53ad481a6fe9.rlib(util_helpers.o), archive member 'util_helpers.o' with length 3560 is not mach-o or llvm bitcode file '/.../my_project/target/debug/deps/libcrypto-d7fa53ad481a6fe9.rlib' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: could not compile `my_project` due to previous error
2. 解決辦法:
查看llvm-ar安裝路徑(沒有則需要安裝):
2.1 查看clang:
which clang
結(jié)果如下:
/usr/local/opt/llvm/bin/clang
2.2 查看llvm-ar:
which llvm-ar
結(jié)果如下:
/usr/local/opt/llvm/bin/llvm-ar
2.3 如果沒有安裝llvm-ar,安裝命令如下:
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
arch -x86_64 /usr/local/bin/brew install llvm
export PATH="/usr/local/opt/llvm/bin:$PATH"
2.4 查看是否安裝成功命令:
/usr/local/opt/llvm/bin/llvm-ar --version
結(jié)果如下:
Homebrew LLVM version 16.0.1
Optimized build.
2.5 重新執(zhí)行cargo 命令:
執(zhí)行cargo clean:
sudo cargo clean
執(zhí)行一次帶AR參數(shù)的cargo命令(本人執(zhí)行一次就好了):
AR=/usr/local/opt/llvm/bin/llvm-ar CC=/usr/local/opt/llvm/bin/clang RUST_LOG=info cargo run --example demo --quiet
如果沒有沒有報錯, 后續(xù)就可以使用正常的cargo命令去跑代碼了
如果沒有生效, 可以嘗試刪除掉target之后再試試文章來源:http://www.zghlxwxcb.cn/news/detail-724748.html
#參考文檔: https://github.com/rust-bitcoin/rust-secp256k1/issues/283文章來源地址http://www.zghlxwxcb.cn/news/detail-724748.html
到了這里,關(guān)于【RUST】mac m1編譯rust項目失?。?could not compile `` due to previous error的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!