要用到 c++11,基礎設施建設。。。作個記錄html
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
su
# wget -c http://gnu.mirror.iweb.com/gcc/gcc-4.8.3/gcc-4.8.3.tar.gz
解壓 gcc-4.8.3.tar.gzmysql
# tar -xzvf gcc-4.8.3.tar.gz
解壓出gcc-4.8.3 ,建立gcc-4.8.3 的同級目錄 mkdir gcc-bulidlinux
# ../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報錯c++
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+. web
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specifysql
編譯 gcc 須要 gmp,mpfr,mpc,m4 下載ubuntu
# 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文件夾裏執行configureapp
安裝依賴關係:ui
m4->gmp spa
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
同時 vi /etc/ld.so.conf
添加 /usr/local/mpc-1.0.1/lib
ldconfig
進入 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
# 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
使其當即生效便可
1 # make install
# 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/ 線程模型:posix gcc 版本 4.8.3 (GCC) root@melos1305-B85M-DS3H:~# gcc -v 使用內建 specs。 COLLECT_GCC=gcc 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/ 線程模型:posix gcc 版本 4.8.3 (GCC)
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)
std動態庫版本跟不上,這修改/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 GLIBCXX strings /usr/local/gcc-4.8.3/lib64/libstdc++.so.6.0.19 | grep GLIBCXX
3. 若是遇到編譯cpp文件時遇到
root@melos1305-B85M-DS3H:/home/melos1305/lilu# /usr/local/gcc-4.8.3/bin/g++ string.cpp /usr/local/gcc-4.8.3/libexec/gcc/x86_64-unknown-linux-gnu/4.8.3/cc1plus: error while loading shared libraries: libmpc.so.3: cannot open shared object file: No such file or directory
則vi /etc/ld.so.conf
添加/usr/local/mpc-1.0.1/lib
ldconfig
要在mpc安裝完以後補上
4. gcc的安裝文件夾最好不要刪掉,之後萬一不當心搞壞了(好比掛g++,gcc,動態庫的連接掛反了),make install 一下就恢復了, build目錄裏的 config.log 裏記錄當時執行configue腳本的配置
5. 遇到
melos1305@melos1305-B85M-DS3H:~/project/lilu/mysql/mysqlSingleton$ ./MysqlDeal
./MysqlDeal: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.19' not found (required by ./MysqlDeal)
g++ 增長選項 -static-libstdc++
6. 若是是ubuntu系統,能夠直接安裝
http://askubuntu.com/questions/288335/ubuntu-13-04-with-gcc-g-gfortran-4-8-by-default/306472#306472
The following should do the trick:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install g++-4.8
sudo apt-get install g++-4.9
Note, if you receive an error saying that add-apt-repository
does not exist, you can install it via:
sudo apt-get install software-properties-common
1 http://bbs.chinaunix.net/thread-314284-1-1.html 2 http://blog.csdn.net/zjg555543/article/details/7421416 3 https://gcc.gnu.org/install/ 4 https://www.gnu.org/software/gcc/ 5 https://www.gnu.org/software/gcc/mirrors.html