Could not exec the linker `cc` error when running “cargo build”

笑着哭i 提交于 2019-12-19 15:46:43

问题


I just installed Rust on my Mac and rustc --version --verbose displays

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

I cloned a couple of repositories (postgres-extension and erlang-rust-nif) and ran cargo build upon both of them. Both reported the error

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

Additionally, I wasn't able to compile a simple Rust file printing "hello world" using rustc. I was only able to compile them by passing the flags rustc -C linker=gcc hello_world.rs.

clang --version displays

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

gcc --version displays

gcc (Homebrew gcc49 4.9.2_1) 4.9.2

回答1:


It looks like you have installed GCC and LLVM/clang via Homebrew. Checking out the shared macOS configurations, the linker defaults to cc. I have installed the macOS developer tools:

$ 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

This is potentially something that Rust itself could fix, but you'd have to file a bug report / enhancement request. It's possible that you might be able to work around this by symlinking clang as cc, instead of just aliasing it, as aliases probably don't exist in the environment that Rust is calling out from.



来源:https://stackoverflow.com/questions/29023305/could-not-exec-the-linker-cc-error-when-running-cargo-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!