【RUST】mac m1编译rust项目失败: could not compile `` due to previous error

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 arm64clang: 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.1Optimized 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://github.com/rust-bitcoin/rust-secp256k1/issues/283


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部