2011-12-22 118 views
3

我下载了gcc 4.6.2(带有GMP,MPFR和MPC)并做了一个构建。我可以在build/gcc目录中看到g++可执行文件。在OSX Lion上安装gcc 4.6.2:“g ++:错误尝试exec'cc1plus'”

当我尝试使用它

./g++ test.cpp 

我得到以下错误:

g++: error trying to exec 'cc1plus': execvp: No such file or directory

  1. 如何解决这个问题?

  2. 如何在默认情况下使用新建的g ++?

PS。 我按照这些步骤来安装,我没有看到任何错误。

$ export CC=/usr/bin/gcc-4.2 
$ export CXX=/usr/bin/g++-4.2 
$ export CPP=/usr/bin/cpp-4.2 
$ export LD=/usr/bin/ld # not /usr/bin/gcc-4.2!! 

Clean also your $PATH as much as possible: 
$ export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin 
(I don’t know exactly if this is necessary but works fine for me and when you close the Terminal the PATH reverts to its original setting). 

1. Download the GCC, GMP, MPFR, and MPC sources. The links are in the original post. 
2. Save everything in, say, ~/Downloads (or any directory you prefer). 
3. Start the Terminal and run the following commands (change the filenames according to the version you have downloaded): 
$ cd # go to your home directory 
$ mkdir src ; cd src 
$ tar -xzf ~/Downloads/gcc-4.6.1.tar.gz # change the path if you have saved the sources elsewhere! 
$ tar -xjf ~/Downloads/gmp-5.0.2.tar.bz2 
$ tar -xzf ~/Downloads/mpc-0.9.tar.gz 
$ tar -xzf ~/Downloads/mpfr-3.0.1.tar.gz 
$ cd gcc-4.6.1 
$ ln -s ../gmp-5.0.2 gmp 
$ ln -s ../mpc-0.9 mpc 
$ ln -s ../mpfr-3.0.1 mpfr 

4. Now create a build directory in ~/src but **outside** the gcc source tree, so that it can easily cleaned up to restart everything from scratch: 
$ cd ~/src 
$ mkdir build ; cd build 
$ ../gcc-4.6.1/configure 
$ make 
$ make install 

回答

3

上的MacOS X 10.7越来越GCC 4.6.2恭喜建 - 我没有成功(即使有,我会建行的4.6.1编译器)。如果我有关于哪里出了问题的笔记,我会与你分享战争故事。

GCC编译安装在某个特定位置(默认为/usr/local,我相信)。当您在构建区域运行时,您必须重定向它以在正确的替代位置找到其可执行文件 - 有选项可以执行此操作。

运行g++ --help-B选项可能是您需要的。我的G ++ 4.6.1给出了这样的输出:

$ g++ -print-search-dirs 
install: /usr/gcc/v4.6.1/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/ 
programs: =/usr/gcc/v4.6.1/libexec/gcc/x86_64-apple-darwin11.1.0/4.6.1/:/usr/gcc/v4.6.1/libexec/gcc/x86_64-apple-darwin11.1.0/4.6.1/:/usr/gcc/v4.6.1/libexec/gcc/x86_64-apple-darwin11.1.0/:/usr/gcc/v4.6.1/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/:/usr/gcc/v4.6.1/lib/gcc/x86_64-apple-darwin11.1.0/:/usr/gcc/v4.6.1/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/../../../../x86_64-apple-darwin11.1.0/bin/x86_64-apple-darwin11.1.0/4.6.1/:/usr/gcc/v4.6.1/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/../../../../x86_64-apple-darwin11.1.0/bin/ 
libraries: =/usr/gcc/v4.6.1/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/:/usr/gcc/v4.6.1/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/../../../../x86_64-apple-darwin11.1.0/lib/x86_64-apple-darwin11.1.0/4.6.1/:/usr/gcc/v4.6.1/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/../../../../x86_64-apple-darwin11.1.0/lib/:/usr/gcc/v4.6.1/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/../../../x86_64-apple-darwin11.1.0/4.6.1/:/usr/gcc/v4.6.1/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/../../../:/lib/x86_64-apple-darwin11.1.0/4.6.1/:/lib/:/usr/lib/x86_64-apple-darwin11.1.0/4.6.1/:/usr/lib/ 
$ 

我指定--prefix=/usr/gcc/v4.6.1,当我跑configure。 (提示:配置的前缀应该在执行构建时不存在,或者路径不应该包含任何符号链接 - 因为GCC会在二进制文件中构建“实际路径”(解析所有符号链接),而不是在命令行上给出的值。如果你有任何计划在不同的机器上使用代码,这一点很重要。)

+0

make install似乎没有触及现有的g ++安装。当我去'print-search-dirs'时,所有的东西都会反映到默认出现的4.2.1。我的版本位于一个名为build的本地目录中,我不知道如何继续。当我尝试编译一个使用'build/gcc/g ++ test.cc'的示例程序时,出现了问题。 – devnull 2011-12-22 16:33:17

+0

如果您查看GCC在忙于编译时执行的命令,您会发现它使用'-B'选项将其指向其组成部分的位置。你需要做同样的事情,或者使用已安装的版本,因为你没有提到前缀,可能在'/ usr/local'('/ usr/local/bin/g ++')中。您可以通过重新安排路径来安排使用它,而不是'/ usr/bin/g ++',因此'/ usr/local/bin'位于'/ usr/bin'之前。 (我的PATH在系统目录之前有'/ usr/gcc/v4.6.1/bin';它还有我的'$ HOME/bin'目录和一些位于系统目录前面的目录。) – 2011-12-22 17:56:22