linux gcc 源码安装

来源:互联网 发布:温州淘宝店主猝死事件 编辑:程序博客网 时间:2024/05/16 08:35

gcc源码获取:

wget ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.8.2/gcc-4.8.2.tar.bz2


解压缩源代码包,进入gcc-4.8.2目录,执行./contrib/download_prerequisities脚本会自动下载三个依赖库别为gmp-4.3.2、mpfr-2.4.2、mpc-0.8.1,也可以通过如下地址离线下载安装:

ftp://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.bz2
http://www.mpfr.org/mpfr-2.4.2/mpfr-2.4.2.tar.bz2
http://www.multiprecision.org/mpc/download/mpc-0.8.1.tar.gz

如果是通过脚本自动下载的依赖库,则会在gcc-4.8.2目录下生成gmp、mpfr和mpc三个目录,分别安装即可

3.安装gmp

[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. cd gmp  
  2. mkdir build  
  3. cd build  
  4. ../configure --prefix=/usr/local/gcc-4.9.3/gmp-4.3.2  

su获取root权限,执行安装
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. make && make install  
4.安装mpfr

回到gcc-4.8.2目录进入mpfr目录

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. cd ../../mpfr  
  2. mkdir build  
  3. cd build  
  4. ../configure --prefix=/usr/local/gcc-4.9.3/mpfr-2.4.2 --with-gmp=/usr/local/gcc-4.9.3/gmp-4.3.2  

su获取root权限,执行安装
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. make && make install  

5.安装mpc

回到gcc-4.8.2目录进入mpc目录

[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. cd ../../mpc  
  2. mkdir build  
  3. cd build  
  4. ../configure --prefix=/usr/local/gcc-4.9.3/mpc-0.8.1 --with-mpfr=/usr/local/gcc-4.9.3/mpfr-2.4.2 --with-gmp=/usr/local/gcc-4.9.3/gmp-4.3.2  

su获取root权限,执行安装
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. make && make install  

6.添加共享库路径,su到root编辑ld.so.conf文件,添加如下内容到文件中:

/usr/local/gcc-4.9.3/gmp-4.3.2/lib
/usr/local/gcc-4.9.3/mpfr-2.4.2/lib
/usr/local/gcc-4.9.3/mpc-0.8.1/lib

保存退出,执行ldconfig命令

7.编译GCC4.8.2

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. cd ../..  
  2. mkdir build  
  3. cd build  
  4. ../configure --prefix=/usr/local/gcc-4.9.3 --enable-threads=posix --disable-checking --enable-languages=c,c++ --disable-multilib --enable-plugin --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --enable-linker-build-id --with-linker-hash-style=gnu --disable-libunwind-exceptions --enable-gnu-unique-object --disable-libgcj --with-ppl --with-cloog --with-system-zlib --enable-__cxa_atexit --with-gmp=/usr/local/gcc-4.9.3/gmp-4.3.2 --with-mpfr=/usr/local/gcc-4.9.3/mpfr-2.4.2 --with-mpc=/usr/local/gcc-4.9.3/mpc-0.8.1

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.3/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC)


换root,执行make && make install,开始漫长的等待......

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. make && make install  

8.卸载旧版本
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. yum remove gcc  
  2. yum remove gcc-c++  
  3. updatedb  

链接到新版本
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. cd /usr/bin  
  2. ln -s /usr/local/gcc/bin/gcc gcc  
  3. ln -s /usr/local/gcc/bin/g++ g++   

添加man帮助

vi /etc/man.config

添加gcc的man路径到配置文件中

MANPATH /usr/local/gcc/share/man

保存退出即可生效,可使用man gcc查看帮助



然后是典型的configure,make,install三步曲。

../trunk/configure --prefix=/usr/local/gcc-4.7 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++
  --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.0 --with-mpc=/usr/local/mpc-0.9

make

make check(可选)

sudo make install

经过漫长的等待:

/usr/local/gcc-4.7/bin/g++ -v
使用内建 specs。
COLLECT_GCC=/usr/local/gcc-4.7/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/gcc-4.7/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper
目标:x86_64-unknown-linux-gnu
配置为:../trunk/configure --prefix=/usr/local/gcc-4.7 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.0 --with-mpc=/usr/local/mpc-0.9
线程模型:posix
gcc 版本 4.7.0 20120113 (experimental) (GCC)



GMP:                  http://down.admin5.com/edu_program/c/71472.html

GNU MP 是用C 语言写成的一个便携式库,它可以进行整数、有理数和浮点数的任意精度算术,其目标是为所有需要不能由基本C 类型直接支持的多精度类型的应用提供可能最快的算术。

MPFR:               http://www.holoborodko.com/pavel/mpfr/#intro

MPFR library allows user to conduct floating-point calculations with virtually any (restricted by available memory only) precision with correct rounding.

MPC:                  


0 0
原创粉丝点击