我下載了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