2011-12-22 119 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