【问题标题】:Could not exec the linker `cc` error when running "cargo build"运行“cargo build”时无法执行链接器`cc`错误
【发布时间】:2015-05-15 09:47:43
【问题描述】:

我刚刚在我的 Mac 上安装了 Rust,rustc --version --verbose 显示

rustc 1.0.0-nightly (91bdf23f5 2015-03-09) (built 2015-03-08)
binary: rustc
commit-hash: 91bdf23f504f79ed59617cde3dfebd3d5e39a476
commit-date: 2015-03-09
build-date: 2015-03-08
host: x86_64-apple-darwin
release: 1.0.0-nightly

我克隆了几个存储库(postgres-extensionerlang-rust-nif)并在它们两个上运行 cargo build。都报错了

error: could not exec the linker `cc`: No such file or directory (os error 2)
error: aborting due to previous error

此外,我无法使用 rustc 编译打印 "hello world" 的简单 Rust 文件。我只能通过传递标志 rustc -C linker=gcc hello_world.rs 来编译它们。

clang --version 显示

clang version 3.4.2  (http://llvm.org/git/llvm.git 5c6aa738fb3325ae499454877f1e2926d2368135)
Target: x86_64-apple-darwin12.2.1
Thread model: posix

gcc --version 显示

gcc (Homebrew gcc49 4.9.2_1) 4.9.2

【问题讨论】:

  • which cc 返回什么?
  • 目前我在我的.bash_profile 中创建了一个alias 作为alias cc=gcc。因此它什么也不返回。

标签: macos linker rust rust-cargo


【解决方案1】:

看起来您已经通过 Homebrew 安装了 GCC 和 LLVM/clang。查看shared macOS configurations,链接器默认为cc。我已经安装了 macOS 开发者工具:

$ clang --version
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

$ cc --version
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

这可能是 Rust 本身可以修复的问题,但您必须提交错误报告/增强请求。您可能可以通过将clang 符号链接为cc 来解决这个问题,而不是仅仅给它起别名,因为在 Rust 调用的环境中可能不存在别名。

【讨论】:

  • 我通过 OSX 命令行工具重新安装了 llvmgcc 并且运行良好。
  • 就像@abips 在 OSX 中所做的那样,我在 LInux 中安装了 gcc,它解决了这个问题。
  • 为了后代,问题已由sudo apt-get install gcc在debian上修复
猜你喜欢
  • 1970-01-01
  • 2010-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-21
  • 1970-01-01
  • 1970-01-01
  • 2014-12-10
相关资源
最近更新 更多