How to upgrade gcc to support C++11 under linux
Since the main platform of the work was changed to linux, and because there is no relatively new gcc in the source, linux only has 4.4.7, and we used C++11, so we had to upgrade it ourselves. The upgrade method is relatively simple, but it is time-consuming.
1. Download the latest source package of gcc
wget ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-6.3.0/gcc-6.3.0.tar.bz2
2. Unzip tar -jxf gcc-6.3.0.tar.bz2
3. cd gcc-6.3.0
4. Modify the ./contrib/download_prerequisites script and change the path inside to
http://www.mirrorservice.org/sites/sourceware.org/pub/gcc/infrastructure/ , the original path download source speed is super slow! run download_prerequisites
Script, ./contrib/download_prerequisites , this script will automatically download the required dependencies and libraries for you
5. 运行 ./configure --prefix=/usr/local --enable-checking=release
--enable-languages=c,c++ --disable-multilib
6. make & make install
After installation, there is a prompt:
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.
The program compiled here runs as a prompt:
$ ./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)
Solution:
$ LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
$ export LD_LIBRARY_PATH