1.1 获取安装包并解压
wget http://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.bz2
tar -jxvf gcc-4.8.2.tar.bz2
1.2 下载编译GCC所依赖的源码库,使用到一个特殊的脚本
cd gcc-4.8.2
./contrib/download_prerequisites
将在./contrib目录下,下载三个源码库:
gmp-4.3.2 mpfr-2.4.2 mpc-0.8.1
1.3 编译安装上述三个依赖库
注意:没有安装到/usr/lib默认的系统目录,所以
稍后编译GCC的时候,需要指定LIB库目录,使用指令如下:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib
./configure --prefix=/usr/local/gmp-4.3.2
make
make install
./configure --prefix=/usr/local/mpfr-2.4.2 --with-gmp=/usr/local/gmp-4.3.2/
make
make install
./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
make install
1.4 建立一个目录供编译出的文件存放
mkdir gcc-build-4.8.2
cd gcc-build-4.8.2
1.5开始编译GCC
指定依赖库的路径
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-
4.3.2/lib:/usr/local/mpfr-2.4.2/lib
../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib --
with-gmp=/usr/local/gmp-4.3.2/ --with-mpfr=/usr/local/mpfr-2.4.2/ --with-
mpc=/usr/local/mpc-0.8.1/
make
make install
1.6 测试版本
gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/i686-pc-linux-gnu/4.8.2/lto-wrapper
目标:i686-pc-linux-gnu
配置为:../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
--with-gmp=/usr/local/gmp-4.3.2/ --with-mpfr=/usr/local/mpfr-2.4.2/ --with-
mpc=/usr/local/mpc-0.8.1/
线程模型:posix
gcc 版本 4.8.2 (GCC)
1.7例子编译
#include
#include
int main()
{
std::shared_ptr
std::cout << *pInt << std::endl;
return 0;
}
g++ -std=c++11 test.cpp
/usr/local/libexec/gcc/i686-pc-linux-gnu/4.8.2/cc1plus: error while loading shared
libraries: libmpc.so.2: cannot open shared object file: No such file or directory
原因libmpc.so.2并没有安装到/usr/lib系统库目录,而是安装在/usr/local/mpc-0.8.1目录下,
所以需要执行如下的命令:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-
4.3.2/lib:/usr/local/mpfr-2.4.2/lib