我应该如何解决-liconv'找不到库:库。运行“货物构建”时的错误?

发布于 2025-01-19 18:23:08 字数 583 浏览 5 评论 0原文

通过以下命令安装生锈和货物...

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蘑菇王子 2025-01-26 18:23:08

第一步是通过 Homebrew 安装 libiconv:

brew install libiconv

请注意,输出显示了一些奇怪的内容:

==> Caveats
libiconv is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have libiconv first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/libiconv/bin:$PATH"' >> ~/.zshrc

For compilers to find libiconv you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/libiconv/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/libiconv/include"

我无法拼凑出完整的解释,但这与 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 中:

export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix)/lib:$(brew --prefix)/opt/libiconv/lib

然后正确检测到 libiconv

First step is to install libiconv via Homebrew:

brew install libiconv

Notice that the output is saying something weird:

==> Caveats
libiconv is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have libiconv first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/libiconv/bin:$PATH"' >> ~/.zshrc

For compilers to find libiconv you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/libiconv/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/libiconv/include"

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 system libiconv 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 your LIBRARY_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:

export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix)/lib:$(brew --prefix)/opt/libiconv/lib

Afterwards libiconv is detected correctly.

月亮坠入山谷 2025-01-26 18:23:08

如果您安装了 GNU gcc,或者任何非 Apple C 编译器,则可能会导致此问题。

除了执行其他答案建议的操作(brew install libiconv)之外,还要检查您的 cc 命令是 Apple clang 还是 gcc 的版本。您可以使用 which -a cc 来完成此操作。

您基本上可以通过运行强制 cc 成为 apple clang 版本:

export PATH="/usr/bin/:$PATH"

然后 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 your cc command is Apple clang or a version of gcc. You can do this with which -a cc.

You can basically force cc to be the apple clang version by running:

export PATH="/usr/bin/:$PATH"

Then rust should work

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文