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

文章描述了一种在执行Cargo命令时遇到的链接错误,特别是与`cc`和`llvm-ar`相关的错误。作者提供了检查和安装llvm-ar的步骤,并通过设置环境变量解决了arm64架构的编译问题。最后,建议清理目标目录并重新执行Cargo命令以确保问题解决。
该文章已生成可运行项目,

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

本文章已经生成可运行项目
error[E0463]: can't find crate for `core` | = note: the `x86_64-pc-windows-msvc` target may not be installed = help: consider downloading the target with `rustup target add x86_64-pc-windows-msvc` For more information about this error, try `rustc --explain E0463`. error: could not compile `cfg-if` (lib) due to 1 previous error warning: build failed, waiting for other jobs to finish... error[E0463]: can't find crate for `std` | = note: the `x86_64-pc-windows-msvc` target may not be installed = help: consider downloading the target with `rustup target add x86_64-pc-windows-msvc` error: could not compile `serde_core` (build script) due to 1 previous error error: could not compile `zerocopy` (build script) due to 1 previous error error: could not compile `quote` (build script) due to 1 previous error error: could not compile `proc-macro2` (build script) due to 1 previous error error: could not compile `litemap` (lib) due to 1 previous error error: could not compile `itoa` (lib) due to 1 previous error error: could not compile `smallvec` (lib) due to 1 previous error error: could not compile `unicode-ident` (lib) due to 1 previous error error: could not compile `writeable` (lib) due to 1 previous error error: could not compile `windows-link` (lib) due to 1 previous error error: could not compile `stable_deref_trait` (lib) due to 1 previous error error: could not compile `icu_properties_data` (build script) due to 1 previous error error: could not compile `serde` (build script) due to 1 previous error error: could not compile `icu_normalizer_data` (build script) due to 1 previous error error: could not compile `memchr` (lib) due to 1 previous error 那我有这个库却报这个错
11-02
error[E0463]: can't find crate for `core` | = note: the `x86_64-pc-windows-msvc` target may not be installed = help: consider downloading the target with `rustup target add x86_64-pc-windows-msvc` error[E0463]: can't find crate for `std` | = note: the `x86_64-pc-windows-msvc` target may not be installed = help: consider downloading the target with `rustup target add x86_64-pc-windows-msvc` For more information about this error, try `rustc --explain E0463`. error: could not compile `smallvec` (lib) due to 1 previous error warning: build failed, waiting for other jobs to finish... error: could not compile `serde_core` (build script) due to 1 previous error error: could not compile `writeable` (lib) due to 1 previous error error: could not compile `litemap` (lib) due to 1 previous error error: could not compile `cfg-if` (lib) due to 1 previous error error: could not compile `unicode-ident` (lib) due to 1 previous error error: could not compile `quote` (build script) due to 1 previous error error: could not compile `zerocopy` (build script) due to 1 previous error error: could not compile `proc-macro2` (build script) due to 1 previous error error: could not compile `itoa` (lib) due to 1 previous error error: could not compile `stable_deref_trait` (lib) due to 1 previous error error: could not compile `icu_normalizer_data` (build script) due to 1 previous error error: could not compile `serde` (build script) due to 1 previous error error: could not compile `windows-link` (lib) due to 1 previous error error: could not compile `icu_properties_data` (build script) due to 1 previous error error: could not compile `memchr` (lib) due to 1 previous error
11-02
PS F:\Programmer\python\AI_Manager\frontend\my-tauri-app> npx tauri dev Running BeforeDevCommand (`npm run dev`) > my-tauri-app@0.0.0 dev > vite VITE v7.1.12 ready in 273 ms ➜ Local: http://localhost:5173/ ➜ Network: use --host to expose Running DevCommand (`cargo run --no-default-features --color always --`) Info Watching F:\Programmer\python\AI_Manager\frontend\my-tauri-app\src-tauri for changes... Compiling proc-macro2 v1.0.103 Compiling unicode-ident v1.0.22 Compiling quote v1.0.41 Compiling cfg-if v1.0.4 Compiling serde_core v1.0.228 Compiling zerocopy v0.8.27 Compiling smallvec v1.15.1 Compiling litemap v0.8.1 Compiling writeable v0.6.2 Compiling windows-link v0.2.1 Compiling itoa v1.0.15 Compiling serde v1.0.228 Compiling stable_deref_trait v1.2.1 Compiling memchr v2.7.6 Compiling icu_normalizer_data v2.1.1 Compiling siphasher v1.0.1 error[E0463]: can't find crate for `std` | = note: the `x86_64-pc-windows-msvc` target may not be installed = help: consider downloading the target with `rustup target add x86_64-pc-windows-msvc` For more information about this error, try `rustc --explain E0463`. error: could not compile `quote` (build script) due to 1 previous error warning: build failed, waiting for other jobs to finish... error[E0463]: can't find crate for `core` | = note: the `x86_64-pc-windows-msvc` target may not be installed = help: consider downloading the target with `rustup target add x86_64-pc-windows-msvc` error: could not compile `cfg-if` (lib) due to 1 previous error error: could not compile `itoa` (lib) due to 1 previous error error: could not compile `proc-macro2` (build script) due to 1 previous error error: could not compile `unicode-ident` (lib) due to 1 previous error error: could not compile `windows-link` (lib) due to 1 previous error error: could not compile `zerocopy` (build script) due to 1 previous error error: could not compile `smallvec` (lib) due to 1 previous error error: could not compile `serde_core` (build script) due to 1 previous error error: could not compile `litemap` (lib) due to 1 previous error error: could not compile `writeable` (lib) due to 1 previous error error: could not compile `serde` (build script) due to 1 previous error error: could not compile `stable_deref_trait` (lib) due to 1 previous error error: could not compile `memchr` (lib) due to 1 previous error error: could not compile `icu_normalizer_data` (build script) due to 1 previous error error: could not compile `siphasher` (lib) due to 1 previous error 程序会在哪里找需要的库,我有需要的库但程序找不到
11-02
Microsoft Windows [版本 10.0.26100.4061] (c) Microsoft Corporation。保留所有权利。 C:\Users\32064>d: D:\>cd zluda D:\zluda>cd ZLUDA-master D:\zluda\ZLUDA-master>cargo build --release Compiling proc-macro2 v1.0.92 Compiling getrandom v0.3.3 Compiling serde v1.0.217 Compiling semver v1.0.23 Compiling syn v1.0.109 Compiling windows_x86_64_msvc v0.52.6 Compiling anyhow v1.0.89 Compiling num-traits v0.2.19 Compiling either v1.13.0 Compiling libc v0.2.171 Compiling version_check v0.9.5 Compiling hashbrown v0.15.2 error: linker `link.exe` not found | = note: program not found note: the msvc targets depend on the msvc linker but `link.exe` was not found note: please ensure that Visual Studio 2017 or later, or Build Tools for Visual Studio were installed with the Visual C++ option. note: VS Code is a different product, and is not sufficient. error: could not compile `semver` (build script) due to 1 previous error warning: build failed, waiting for other jobs to finish... error: could not compile `serde` (build script) due to 1 previous error error: could not compile `proc-macro2` (build script) due to 1 previous error error: could not compile `getrandom` (build script) due to 1 previous error error: could not compile `syn` (build script) due to 1 previous error error: could not compile `anyhow` (build script) due to 1 previous error error: could not compile `windows_x86_64_msvc` (build script) due to 1 previous error error: could not compile `num-traits` (build script) due to 1 previous error error: could not compile `libc` (build script) due to 1 previous error
07-31
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值