配置:错误:C 编译器无法创建可执行文件

nak*_*aka 16 bash gcc 12.04 12.10

我试图安装 rvm 使用\curl -L https://get.rvm.io | bash -s stable --ruby --autolibs=enable --auto-dotfiles. 它工作正常,直到出现配置错误:

Error running './configure --prefix=/home/nishant/.rvm/rubies/ruby-2.0.0-p247 --disable-install-doc --enable-shared',
please read /home/nishant/.rvm/log/1379591052_ruby-2.0.0-p247/configure.log
There has been an error while running configure. Halting the installation.
Run Code Online (Sandbox Code Playgroud)

以下是上述日志文件的内容:

[2013-09-19 17:15:58] ./configure
current path: /home/nishant/.rvm/src/ruby-2.0.0-p247
command(4): ./configure --prefix=/home/nishant/.rvm/rubies/ruby-2.0.0-p247 --disable-install-doc --enable-shared
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/home/nishant/.rvm/src/ruby-2.0.0-p247':
configure: error: C compiler cannot create executables
See `config.log' for more details
Run Code Online (Sandbox Code Playgroud)

然后我尝试了一个“hello world”C程序,编译时出现以下错误:

nishant@nishant-Inspiron-1545:~$ gcc -g -o hello hello.c 
/usr/local/bin/ld: this linker was not configured to use sysroots
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我不确定为什么会抛出这个错误。我在论坛上找不到满意的答案。有人可以帮忙吗。谢谢

ste*_*ver 13

它看起来像你有一个非标准版本的GNU链接器ld在你的 /usr/local/bin目录(可能是从源代码安装),以及您的PATH环境变量设置使得系统找到该版本的“系统”之前的版本(这应该是/usr/bin/ld) . 如果要使用构建工具的标准系统版本进行构建,则需要调整 PATH 环境变量,以便它/usr/bin提前搜索/usr/local/bin

如果你想永久修复你的 PATH 变量,你需要找出你最初设置它的位置 - 可能在你的 ~/.bashrc 文件中,但其他位置也是可能的。或者,如果您只需要对此构建进行临时修复,则可以尝试

export PATH="/usr/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)

在执行之前在终端中 ./configure

但是,有时您(或您的系统管理员)可能有充分的理由希望您使用来自以下版本的工具/usr/local- 如果是这样,那么您将需要找出为什么ld那里显然与构建链的其余部分不兼容并修复它 - 如果这是工作或学校系统,请联系您的系统管理员或 IT 部门。

  • 通常`/usr/local/bin` 在`PATH` 中排在`/usr/bin` 之前是有充分理由的:如果发行版中的版本优先,那么在本地安装程序是没有意义的。发现问题做得很好,但推荐的解决方案不是更改 PATH,而是删除或修复损坏的 `/usr/local/bin/ld`。 (9认同)
  • 我遇到了同样的错误......这对我不起作用......`which ld`只返回`/usr/bin/ld`......。 (3认同)

ocz*_*sse 10

与上面给出的复杂原因相反,就我而言,这只是没有g++安装的情况。奇怪的是,错误消息与 OP 所描述的相同,即

configure: error: C compiler cannot create executables
Run Code Online (Sandbox Code Playgroud)

无论如何,我通过安装 g++ 解决了这个问题:

sudo apt-get install g++
Run Code Online (Sandbox Code Playgroud)