linux下升级gcc支持C++11的方法
由于工作主要平台换到了linux上,而linux因为源上没有比较新的gcc,只有4.4.7,而我们用到了C++11, 只好自己升级了,升级方法也比较简单,就是耗时间。
1. 下载gcc最新的源码包
wget ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-6.3.0/gcc-6.3.0.tar.bz2
2. 解压缩 tar -jxf gcc-6.3.0.tar.bz2
3. cd gcc-6.3.0
4. 修改./contrib/download_prerequisites脚本,将里边路径改为
http://www.mirrorservice.org/sites/sourceware.org/pub/gcc/infrastructure/,原来路径下载源速度超级慢!运行download_prerequisites
脚本, ./contrib/download_prerequisites ,这个脚本会自动帮你下载所需要的依赖文件和库
5. 运行 ./configure --prefix=/usr/local --enable-checking=release
--enable-languages=c,c++ --disable-multilib
6. make & make install
安装完后有一段提示:
Libraries have been installed in:
/usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
这里编译出来的程序运行为提示:
$ ./ui/client/console/client
./ui/client/console/client: /usr/lib/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ./ui/client/console/client)
./ui/client/console/client: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./ui/client/console/client)
./ui/client/console/client: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by ./ui/client/console/client)
解决方法:
$ LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
$ export LD_LIBRARY_PATH