首先查看INSTALL說明:file:///Users/gerryyang/code/public/gcc-4.8.1/INSTALL/index.html,,然后嘗試編譯:
GMP 4.2+:
ftp://gcc./pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
MPFR 2.4.0+:
ftp://gcc./pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
MPC 0.8.0+:
ftp://gcc./pub/gcc/infrastructure/mpc-0.8.1.tar.gz
根據(jù)提示的順序分別安裝GMP,MPFR和MPC:
step1: ./configure --prefix=/usr/local/gmp-4.3.2; make install
step2: ./configure --prefix=/usr/local/mpfr-2.4.2 --with-gmp=/usr/local/gmp-4.3.2/; make install
注意:step2依賴于step1,,否則會(huì)報(bào)”configure: error: gmp.h can't be found, or is unusable.“的錯(cuò)誤,。
step3: ./configure --prefix=/usr/local/mpc-0.8.1 --with-gmp=/usr/local/gmp-4.3.2/ --with-mpfr=/usr/local/mpfr-2.4.2/; make install
注意:step3同樣依賴于前面的庫,,否則會(huì)報(bào)”configure: error: libgmp not found or uses a different ABI.和configure: error: libmpfr not found or uses a different ABI.“的錯(cuò)誤。
step4: 設(shè)置環(huán)境變量,,export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/gmp-4.3.2/lib/:/usr/local/mpfr-2.4.2/lib/:/usr/local/mpc-0.8.1/lib/
step5:./configure --prefix=/usr/local/gcc-4.8.1/ --enable-threads=posix --disable-checking --with-gmp=/usr/local/gmp-4.3.2/ --with-mpfr=/usr/local/mpfr-2.4.2/ --with-mpc=/usr/local/mpc-0.8.1/ (還是提示找不到,!看來掉坑里了)
3 正確地編譯方法
上述方法在參考[2]是不建議這樣做的:
The difficult way, which is not recommended, is to download the sources for GMP, MPFR and MPC, then configure and install each of them in non-standard locations, then configure GCC with--with-gmp=/some/silly/path/gmp --with-mpfr=/some/silly/path/mpfr --with-mpc=/some/silly/path/mpc,
then be forced to set LD_LIBRARY_PATH=/some/silly/path/gmp:/some/silly/path/mpfr:/some/silly/path/mpc/lib in your environment forever. This is silly and causes major problems for anyone who doesn't understand how dynamic linkers find
libraries at runtime. Do not do this. If building GCC fails when using any of the--with-gmp or--with-mpfr or--with-mpc options then you probably shouldn't be using them.
參考[2]中介紹了更簡單的方法:
Alternatively, after extracting the GCC source archive, simply run the
./contrib/download_prerequisites script in the GCC source directory. That will download the support libraries and create symlinks, causing them to be built automatically as part of the GCC
build process. Set GRAPHITE_LOOP_OPT=yes in the script if you want to build GCC with the Graphite loop optimizations.
- # gcc-4.8.1/contrib/download_prerequisites
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- # General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see http://www./licenses/.
-
- MPFR=mpfr-2.4.2
- GMP=gmp-4.3.2
- MPC=mpc-0.8.1
-
- wget ftp://gcc./pub/gcc/infrastructure/$MPFR.tar.bz2 || exit 1
- tar xjf $MPFR.tar.bz2 || exit 1
- ln -sf $MPFR mpfr || exit 1
-
- wget ftp://gcc./pub/gcc/infrastructure/$GMP.tar.bz2 || exit 1
- tar xjf $GMP.tar.bz2 || exit 1
- ln -sf $GMP gmp || exit 1
-
- wget ftp://gcc./pub/gcc/infrastructure/$MPC.tar.gz || exit 1
- tar xzf $MPC.tar.gz || exit 1
- ln -sf $MPC mpc || exit 1
-
- rm $MPFR.tar.bz2 $GMP.tar.bz2 $MPC.tar.gz || exit 1
前提需要下載wget(使用源碼方式,這里有些"坑",,若不指定--with-ssl=openssl則提示需要安裝GnuTLS)
- ...
- checking for compress in -lz... yes
- checking for gpg_err_init in -lgpg-error... no
- checking for gcry_control in -lgcrypt... no
- checking for libgnutls... no
- configure: error: --with-ssl was given, but GNUTLS is not available.
Note the with-ssl=openssl option in the command above. If you omit that, you will get the following error:
下載wget源代碼地址:
http://www./software/wget/
tar -xzvf wget-1.14.tar.gz
cd wget-1.14
./configure --with-ssl=openssl
make
sudo make install
安裝好wget后,,使用代碼中自帶的腳本下載gcc依賴的文件:
- sh-3.2# pwd
- /Users/gerryyang/code/public/gcc-4.8.1
- sh-3.2# ./contrib/download_prerequisites
- --2013-08-12 22:37:39-- ftp://gcc./pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
- => ‘mpfr-2.4.2.tar.bz2’
- Resolving gcc.... 209.132.180.131
- Connecting to gcc.|209.132.180.131|:21... connected.
- Logging in as anonymous ... Logged in!
- ==> SYST ... done. ==> PWD ... done.
- ==> TYPE I ... done. ==> CWD (1) /pub/gcc/infrastructure ... done.
- ==> SIZE mpfr-2.4.2.tar.bz2 ... 1077886
- ==> PASV ... done. ==> RETR mpfr-2.4.2.tar.bz2 ... done.
- Length: 1077886 (1.0M) (unauthoritative)
-
- 100%[==================================================================================================================================================================>] 1,077,886 194KB/s in 5.7s
-
- 2013-08-12 22:37:51 (185 KB/s) - ‘mpfr-2.4.2.tar.bz2’ saved [1077886]
-
- --2013-08-12 22:37:51-- ftp://gcc./pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
- => ‘gmp-4.3.2.tar.bz2’
- Resolving gcc.... 209.132.180.131
- Connecting to gcc.|209.132.180.131|:21... connected.
- Logging in as anonymous ... Logged in!
- ==> SYST ... done. ==> PWD ... done.
- ==> TYPE I ... done. ==> CWD (1) /pub/gcc/infrastructure ... done.
- ==> SIZE gmp-4.3.2.tar.bz2 ... 1897483
- ==> PASV ... done. ==> RETR gmp-4.3.2.tar.bz2 ... done.
- Length: 1897483 (1.8M) (unauthoritative)
-
- 100%[==================================================================================================================================================================>] 1,897,483 177KB/s in 10s
-
- 2013-08-12 22:38:08 (177 KB/s) - ‘gmp-4.3.2.tar.bz2’ saved [1897483]
-
- --2013-08-12 22:38:09-- ftp://gcc./pub/gcc/infrastructure/mpc-0.8.1.tar.gz
- => ‘mpc-0.8.1.tar.gz’
- Resolving gcc.... 209.132.180.131
- Connecting to gcc.|209.132.180.131|:21... connected.
- Logging in as anonymous ... Logged in!
- ==> SYST ... done. ==> PWD ... done.
- ==> TYPE I ... done. ==> CWD (1) /pub/gcc/infrastructure ... done.
- ==> SIZE mpc-0.8.1.tar.gz ... 544950
- ==> PASV ... done. ==> RETR mpc-0.8.1.tar.gz ... done.
- Length: 544950 (532K) (unauthoritative)
-
- 100%[==================================================================================================================================================================>] 544,950 172KB/s in 3.1s
-
- 2013-08-12 22:38:16 (172 KB/s) - ‘mpc-0.8.1.tar.gz’ saved [544950]
再嘗試編譯gcc,configure成功生產(chǎn)Makefile,,下面可以make install了,。
注意:剛開始沒注意,在源文件目錄(gcc-4.8.1/)下configure后再進(jìn)行make; make install會(huì)出現(xiàn)編譯時(shí)的斷言錯(cuò)誤,,在網(wǎng)上搜了錯(cuò)誤原因暫沒找到具體的解決辦法,。通過查看參考[2]通過另一種方法可以避免上述那個(gè)斷言錯(cuò)誤:
See
Installing GCC: Configuration for the full documentation. A major benefit of running srcdir/configure from outside the source directory (instead of running./configure) is that the source directory
will not be modified in any way, so if your build fails or you want to re-configure and build again, you simply delete everything in the objdir and start again.
For example, configuring and building GCC 4.6.2 should be as simple as:
tar xzf gcc-4.6.2.tar.gz
cd gcc-4.6.2
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-4.6.2/configure --prefix=$HOME/gcc-4.6.2
make
make install
If your build fails and your configure command has lots of complicated options you should try removing options and keep it simple. Do not add lots of configure options you don't
understand, they might be the reason your build fails.
OK,通過上述方法進(jìn)行編譯問題解決,,編譯耗時(shí)1小時(shí)+,,下面是編譯成功后gcc的版本信息:
4 參考
[1]
http:///questions/9450394/how-to-install-gcc-from-scratch-with-gmp-mpfr-mpc-elf-without-shared-librari (講的很清楚)
[2]
http://gcc./wiki/InstallingGCC(找到了光明大道)
http://gcc./install/prerequisites.html(關(guān)于一些依賴的說明)
[3]
http://crosstown./os-x/32-install-and-configure-wget-on-os-x-lion-107 (編譯wget遇到的坑,這里說明了一種解決方法)
[4]
http:///blog/install-wget-on-os-x-lion/ (編譯wget遇到的坑)