我应该如何解决-liconv'找不到库:库。运行“货物构建”时的错误?
通过以下命令安装生锈和货物...
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
我在一个小的“ Hello World” Rust Project上运行货物构建
,并收到以下错误:
= note: ld: library not found for -liconv
collect2: error: ld returned 1 exit status
error: could not compile `hello_world` due to previous error
我尝试了Rustup self卸载然后通过
brew
安装生锈和货物,但是在尝试构建时我会遇到相同的错误。
我正在运行Macos Big Sur 11.6.4。
After installing Rust and Cargo via the following command...
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
I ran cargo build
on a tiny "Hello World" Rust project and got the following error:
= note: ld: library not found for -liconv
collect2: error: ld returned 1 exit status
error: could not compile `hello_world` due to previous error
I've tried rustup self uninstall
then installing Rust and Cargo via brew
, but I get the same error when attempting to build.
I'm running macOS Big Sur 11.6.4.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一步是通过 Homebrew 安装 libiconv:
请注意,输出显示了一些奇怪的内容:
我无法拼凑出完整的解释,但这与 libiconv 有关。 MacOS 提供的 /code> 版本具有错误的符号。在我的系统上找不到 libiconv(是 M1 的东西吗?);尽管如此,brew 拒绝踩操作系统的脚趾,这似乎是一个合理的决定。
然而,这些变量不适用于
cargo
。解决该问题的最佳方法(我发现)是修改您的 LIBRARY_PATH 变量以提供 iconv 的路径。您可能已经必须修改您的
LIBRARY_PATH
(请参阅https://apple.stackexchange.com/questions/40704/homebrew-installed-libraries-how-do-i-use-them)。我所做的是将以下行添加到我的
~/.zshrc
中:然后正确检测到
libiconv
。First step is to install
libiconv
via Homebrew:Notice that the output is saying something weird:
I haven't been able to piece together a complete explanation, but it is something to do with
libiconv
being provided by MacOS in a version that has the wrong symbols. On my systemlibiconv
can't be found (is it a M1 thing?); nevertheless, brew refuses to step on the OSes' toes, which seems a reasonable decision.These variables do not apply to
cargo
however.The best way to solve the problem (that I found) is to modify your
LIBRARY_PATH
variable to provide path to iconv. You might have already had to modify yourLIBRARY_PATH
(see e.g. https://apple.stackexchange.com/questions/40704/homebrew-installed-libraries-how-do-i-use-them).What I did was to add the following line to my
~/.zshrc
:Afterwards
libiconv
is detected correctly.如果您安装了 GNU gcc,或者任何非 Apple C 编译器,则可能会导致此问题。
除了执行其他答案建议的操作(
brew install libiconv
)之外,还要检查您的cc
命令是 Apple clang 还是 gcc 的版本。您可以使用which -a cc
来完成此操作。您基本上可以通过运行强制 cc 成为 apple clang 版本:
然后 rust 应该可以工作
If you've installed GNU gcc, or really any not-Apple C compiler it can cause this issue.
In addition to doing what the other answer recommends (
brew install libiconv
) also check and see if yourcc
command is Apple clang or a version of gcc. You can do this withwhich -a cc
.You can basically force
cc
to be the apple clang version by running:Then rust should work