首页 > 代码库 > 编译安装gcc 4.8.3
编译安装gcc 4.8.3
要用到c++11,基础设施建设。。。
0.系统版本:
root@melos1305-B85M-DS3H:~# cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=12.04 DISTRIB_CODENAME=precise DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS" root@melos1305-B85M-DS3H:~# uname -a Linux melos1305-B85M-DS3H 3.2.0-24-generic #37-Ubuntu SMP Wed Apr 25 08:43:22 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
1. 用root用户
su
2. 下载gcc:
# wget -c http://gnu.mirror.iweb.com/gcc/gcc-4.8.3/gcc-4.8.3.tar.gz
解压 gcc-4.8.3.tar.gz
# tar -xzvf gcc-4.8.3.tar.gz
解压出gcc-4.8.3 ,创建gcc-4.8.3 的同级目录 mkdir gcc-bulid
3. 进入gcc-bulid 执行:
# ../gcc-4.8.3/configure --prefix=/usr/local/gcc-4.8.3 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-6.0.0/ --with-mpfr=/usr/local/mpfr-3.1.2/ --with-mpc=/usr/local/mpc-1.0.1/
configure报错
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
编译 gcc 需要 gmp,mpfr,mpc,m4 下载
# wget -c http://ftp.gnu.org/gnu/m4/m4-latest.tar.xz # wget -c http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.gz # wget -c ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.1.tar.gz # wget -c https://gmplib.org/download/gmp/gmp-6.0.0a.tar.lz.sig
解压后分别新建同级文件夹mkdir gcc-build, m4-bulid, gmp-bulid, mpfr-bulid, mpc-bulid, gmp-bulid,在bulid文件夹里执行configure
安装依赖关系:
m4->gmp,
mpfr->gmp,
mpc->gmp,mpfr
gcc->gmp,mpfr,mpc
分别编译安装:
# m4, ../m4-xxx/configure;make;make check; make install # gmp ../gmp-xxx/configure --prefix=/usr/local/gmp-xxx; make; make check; make install # mpfr ../mpfr-xxx/configure --prefix=/usr/local/mpfr-xxx --with-gmp=/usr/local/gmp-xxx; make; make check; make install # mpc ../mpc-xxx/configure --prefix=/usr/local/mpc-xxx --with-gmp=/usr/local/gmp-xxx --with-mpfr=/usr/local/mpfr-xxx; make; make check; make install
进入gcc-bulid 执行:
# ../gcc-4.8.3/configure --prefix=/usr/local/gcc-4.8.3 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-6.0.0/ --with-mpfr=/usr/local/mpfr-3.1.2/ --with-mpc=/usr/local/mpc-1.0.1/
完成后, gcc-bulid文件夹里有makefile
4. 编译gcc:
# make
g++ 4.8.3 编译不过报错configure: error: cannot compute suffix of object files: cannot compile
需要将mpc、gmp和mpfr目录加入到环境变量中,
# vi /etc/profile
文件末尾加上:export LD_LIBRARY_PATH=/usr/local/mpc-1.0.1/lib:/usr/local/gmp-6.0.0/lib:/usr/local/mpfr-3.1.2/lib
注意修改目录,之后运行
# source /etc/profile
使其立即生效即可
5. 安装gcc:
1 # make install
6. 修改符号链接:
# cd /usr/bin/ # ln -si ln -si /usr/local/gcc-4.8.3/bin/gcc gcc (修改gcc符号链接) # ln -si ln -si /usr/local/gcc-4.8.3/bin/g++ g++ (修改g++符号链接)
最后查看下版本
root@melos1305-B85M-DS3H:~# g++ -v使用内建 specs。COLLECT_GCC=g++COLLECT_LTO_WRAPPER=/usr/local/gcc-4.8.3/libexec/gcc/x86_64-unknown-linux-gnu/4.8.3/lto-wrapper目标:x86_64-unknown-linux-gnu配置为:../gcc-4.8.3/configure --prefix=/usr/local/gcc-4.8.3 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-6.0.0/ --with-mpfr=/usr/local/mpfr-3.1.2/ --with-mpc=/usr/local/mpc-1.0.1/线程模型:posixgcc 版本 4.8.3 (GCC) root@melos1305-B85M-DS3H:~# gcc -v使用内建 specs。COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/usr/local/gcc-4.8.3/libexec/gcc/x86_64-unknown-linux-gnu/4.8.3/lto-wrapper目标:x86_64-unknown-linux-gnu配置为:../gcc-4.8.3/configure --prefix=/usr/local/gcc-4.8.3 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-6.0.0/ --with-mpfr=/usr/local/mpfr-3.1.2/ --with-mpc=/usr/local/mpc-1.0.1/线程模型:posixgcc 版本 4.8.3 (GCC)
7. 其他:
1. 好像可以加也可以不加,看情况,g++调用不了动态库就加上,修改库的路径环境变量:
# vi /etc/profile # 添加 export LD_LIBRARY_PATH=/usr/local/gcc-4.8.3/lib:/usr/local/mpc-1.0.1/lib:/usr/local/gmp-6.0.0/lib:/usr/local/mpfr-3.1.2/lib # source /etc/profile
2. 如果遇到
melos1305@melos1305-B85M-DS3H:~/project/cocos2dx/cocos2d-x-3.1/build/linux-build/bin/cpp-empty-test$ ./cpp-empty-test ./cpp-empty-test: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.18‘ not found (required by ./cpp-empty-test)
stl动态库版本跟不上,这修改/usr/lib/下的链接
# ln -si /usr/local/gcc-4.8.3/lib/x86_64-linux-gnu/libstdc++.so.6.0.19 libstdc++.so.6 #链接到gcc-4.8.3的动态库
挂链接,服务端的ubuntu是64位,所以lib64/libstd++.so.6的默认版本不够,需要支持到GLIBCXX_3.4.18以上, 查看GLIBCXX版本信息:
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXXstrings /usr/local/gcc-4.8.3/lib64/libstdc++.so.6.0.19 | grep GLIBCXX
3. gcc的安装文件夹可以不用删掉,以后万一不小心搞坏了(比如挂g++,gcc,动态库的链接挂反了),make install 一下就恢复了
8. 参考:
1 http://bbs.chinaunix.net/thread-314284-1-1.html2 http://blog.csdn.net/zjg555543/article/details/74214163 https://gcc.gnu.org/install/4 https://www.gnu.org/software/gcc/5 https://www.gnu.org/software/gcc/mirrors.html
编译安装gcc 4.8.3