macports gcc选择错误试图执行i686-apple-darwin11-llvm-gcc-4.2


13

我正在OS X 10.7(Lion)上工作。我已经从macports安装了gcc 4.7:

sudo port install gcc47

它似乎工作正常:

$ /opt/local/bin/gcc-mp-4.7 -v
(...)
gcc version 4.7.0 (GCC) 

现在,我试图通过使用端口选择来更改默认编译器:

$ sudo port select gcc mp-gcc47
Selecting 'mp-gcc47' for 'gcc' succeeded. 'mp-gcc47' is now active.

它将gcc二进制文件复制到/ opt / local / bin / gcc,它可以正常工作:

$ /opt/local/bin/gcc -v
(...)
gcc version 4.7.0 (GCC) 

它还会更改默认gcc:

$ which gcc
/opt/local/bin/gcc

但是运行此默认值不起作用:

$ gcc -v
gcc-mp-4.7: error trying to exec '/opt/local/bin/i686-apple-darwin11-llvm-gcc-4.2': execvp: No such file or directory

此二进制文件“ i686-apple-darwin11-llvm-gcc-4.2”是Apple最初提供的gcc版本;我不知道为什么它尝试在/ opt / local / bin中查看它,甚至根本不尝试运行它。如果创建符号链接,它会简单地调用此二进制文件,这不是我想要的:

$ sudo ln -s /usr/bin/i686-apple-darwin11-llvm-gcc-4.2 /opt/local/bin
$ gcc -v
(...)
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)

如何通过简单地调用“ gcc”来使gcc正常工作?据我所知,较旧的OS X中有gcc_select工具,但我的系统没有。

Answers:


17

最有可能的原因是bash已gcc散列。

$ hash

查看哪些命令被散列。如果/ usr / bin / gcc出现在列表中,请运行

$ hash gcc

重新整理gcc。之后,如果您运行hash,则应该看到/ opt / local / bin / gcc ,而运行gcc应该运行macports版本-当然要选择它。

/ B2S

编辑:对于zsh用户,请运行$ rehash以刷新整个哈希值。


1
好吧,我什至不知道这种机制的存在。谢谢!
MariuszPluciński2012年

0

我也有同样的问题,但这不是正确的解决方案-我希望有人能对此提出建议。目前,直接调用它:

$ gcc-mp-4.7 -v
Using built-in specs.
COLLECT_GCC=gcc-mp-4.7
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin11/4.7.0/lto-wrapper
Target: x86_64-apple-darwin11
    Configured with: ../gcc-4.7.0/configure --prefix=/opt/local --build=x86_64-apple-darwin11 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc47 --includedir=/opt/local/include/gcc47 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.7 --with-libiconv-prefix=/opt/local --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.7 --with-gxx-include-dir=/opt/local/include/gcc47/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --enable-stage1-checking --disable-multilib --enable-lto --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts gcc47 4.7.0_3'
Thread model: posix
gcc version 4.7.0 (MacPorts gcc47 4.7.0_3) 

希望在找到永久解决方案之前有所帮助

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.