我下载了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
如何解决这个问题?
如何在默认情况下使用新建的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
make install似乎没有触及现有的g ++安装。当我去'print-search-dirs'时,所有的东西都会反映到默认出现的4.2.1。我的版本位于一个名为build的本地目录中,我不知道如何继续。当我尝试编译一个使用'build/gcc/g ++ test.cc'的示例程序时,出现了问题。 – devnull 2011-12-22 16:33:17
如果您查看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