http://blog.sina.com.cn/s/blog_493667730100zt6n.html
从svn checkout svn://gcc.gnu.org/svn/gcc/trunk拿了GCC的最新代码,打算编译了学东西习学习C++ 11的东西,结果在configure的时候出现如下问题:
wget ftp://gnu.mirror.iweb.com/gmp/gmp-4.3.2.tar.gz
wget http://www.mpfr.org/mpfr-current/mpfr-3.1.4.tar.gz
wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
../gmp-4.3.2/configure --prefix=/usr/local/gmp-4.3.2
makesudo make install
mpfr和mpc的安装方法与gmp类似。不过要注意配置的时候要把gmp与mpfr的依赖关系选项加进去,具体配置命令如下:
../mpfr-3.1.4/configure --prefix=/usr/local/mpfr-3.1.4 --with-gmp=/usr/local/gmp-4.3.2
../mpc-1.0.3/configure --prefix=/usr/local/mpc-1.0.3 --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-3.1.4
安装好这三个库之后,就可以正式开始安装gcc了。
当然了链接的时候,需要刚刚编译的3个lib。
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-1.0.3/lib:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-3.1.4/lib
然后是典型的configure,make,install三步曲。
../trunk/configure --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++
--with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-3.1.4 --with-mpc=/usr/local/mpc-1.0.3
make
make check(可选)
sudo make install
经过漫长的等待:
#g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/gcc-4.8.2/libexec/gcc/x86_64-unknown-linux-gnu/4.8.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/usr/local/gcc-4.8.2 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-4.3.2/ --with-mpfr=/usr/local/mpfr-3.1.4/ --with-mpc=/usr/local/mpc-1.0.3/
Thread model: posix
gcc version 4.8.2 (GCC)
开始C++ 11学习了。
今天在编译完一个小程序,运行时报错:
[david@localhost programmer]$ prog1
prog1: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by prog1)
[david@localhost programmer]$ strings /usr/lib64/libstdc++.so.6|grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH
最高到了3.4.13,没有3.4.15版.
我是自己从源代码编译的gcc 4.8.2,应该是sudo make install没有抓到这个包.
在网上搜了搜,参考这篇文章:http://stackoverflow.com/questions/5216399/usr-lib-libstdc-so-6-version-glibcxx-3-4-15-not-found,把问题解决了:
1.在当时make的目录下找到如下文件:
gcc-build-4.8.2/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.18,
strings libstdc++.so.6.0.18| strings /usr/lib64/libstdc++.so.6|grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH
包括了.15,应该可以!
把该文件拷贝到了/usr/lib64下.
然后将libstdc++.so.6指向libstdc++.so.6.0.18:
[root@localhost lib64]# rm -r libstdc++.so.6
rm: remove symbolic link `libstdc++.so.6'? y
[root@localhost lib64]# ln -s libstdc++.so.6.0.18 libstdc++.so.6
再次运行程序就好使了!