1. 问题描述
执行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
结果如下:
/usr/local/opt/llvm/bin/clang
2.2 查看llvm-ar:
which llvm-ar
结果如下:
/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
结果如下:
Homebrew LLVM version 16.0.1
Optimized build.
2.5 重新执行cargo 命令:
执行cargo clean:
sudo cargo clean
执行一次带AR参数的cargo命令(本人执行一次就好了):
AR=/usr/local/opt/llvm/bin/llvm-ar CC=/usr/local/opt/llvm/bin/clang RUST_LOG=info cargo run --example demo --quiet
如果没有没有报错, 后续就可以使用正常的cargo命令去跑代码了
如果没有生效, 可以尝试删除掉target之后再试试文章来源:https://www.toymoban.com/news/detail-724748.html
#参考文档: https://github.com/rust-bitcoin/rust-secp256k1/issues/283文章来源地址https://www.toymoban.com/news/detail-724748.html
到了这里,关于【RUST】mac m1编译rust项目失败: could not compile `` due to previous error的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!