gcc updated version (Your C++ compiler does NOT fully support C++11)

1. Source code compile and install gcc-4.9.2
1. Download gcc source code package

wget http://ftp.gnu.org/gnu/gcc/gcc-4.9.2/gcc-4.9.2.tar.gz

2. Unzip the compressed package

tar -zxvf gcc-4.9.2.tar.gz

3. Download the dependency packages required for compilation.
This step can be completed in two ways:

a) If Linux has a network connection, directly like this:

cd gcc-4.9.2
./contrib/download_prerequisites

b) If Linux does not have a network connection (my host and virtual machine are Host-only and cannot be connected to the Internet, so think of another way), then use Windows to download these packages on the Internet:

ftp://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.bz2

http://www.mpfr.org/mpfr-2.4.2/mpfr-2.4.2.tar.bz2

http://www.multiprecision.org/mpc/download/mpc-0.8.1.tar.gz

Then unzip and move to gcc-4.8.1:

tar -xjf gmp-4.3.2.tar.bz2

tar -xjf mpfr-2.4.2.tar.bz2

tar -xzf mpc-0.8.1.tar.gz

4. Compile and install gcc

sudo apt install gcc-c++  glibc-static gcc //为避免出错建议安装此包
./configure --prefix=/usr/local/gcc  --enable-bootstrap  --enable-checking=release --enable-languages=c,c++ --disable-multilib
make
make install

Compilation parameter description:

--Prefix=/usr/local/ specify the installation path

--Enable-bootstrap Here is an explanation of this parameter from some online literature: use the program generated by the first compilation for the second compilation, and then use the generated program for the third compilation, and check and compare the second and third The correctness of the secondary results means that redundant compilation checks are performed. In a non-cross-compilation environment, the value has been set to enable by default, and you don't need to display the designation; in a cross-compilation environment, you need to display the value to disable.

--Enable-checking=release Use the standard of the software release version to check the consistency of the code generated during compilation; setting this option to enable will not change the binary result generated by the compiler, but it will increase the compilation time; this option Only the gcc compiler is supported; in general, for the above option, the hardware configuration of the machine is low, and children's shoes who do not want to wait too long for the compilation time can be set to disable; but this will increase the risk of unexpected errors. So it should be used with caution. You can set --disable-bootstrap and --disable-checking at the same time, which is very helpful for speeding up the compilation process.

--Enable-threads=posix As the name suggests, enable posix standard thread support. To make the program run correctly on the Linux distribution that conforms to the POSIX specification, you should enable this option, depending on the type of host or target operating system, other available values There are: aix, dec, solaris, win32, etc. If you are other UNIX-like systems, you need to set the corresponding values.

--Enable-languages=c, the high-level language types and runtime libraries supported by c++, all languages ​​that can be set include ada, c, c++, Fortran, java, objc, obj-c++, GO and other languages. Only c and c++ are enabled here, because the more languages ​​supported, the more corresponding static and dynamic libraries need to be installed, as well as a variety of dependent libraries, which will make management difficult and the size will become huge.

--Disable-multilib If your operating system is 32-bit, it is set to disable by default, which means that gcc can only generate 32-bit executable programs; if your operating system is 64-bit, it is already set to enable by default. This means that when compiling other source files with gcc, you can use the -m32 option to determine whether to generate 32-bit machine code. If you are on a 64-bit system, to disable the generation of 32-bit code, set --disable-multilib.

--Enable-gather-detailed-mem-stats allows you to collect detailed memory usage information. If you set this parameter to enable, the compiled gcc executable program in the future can be used to output the real-time compiling other programs through the -fmem-report option Memory usage.

--With-long-double-128 specifies that the long double type is 128 bits (16 bytes!); if set to without, the long double type will be 64 bits (8 bytes), which will be the same as the ordinary double type. When compiling based on Glib 2.4 or higher, the default is already 128 bits.

5. Follow-up operations

Export environment variables:

gcc --version
#gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16)
vim /etc/profile.d/gcc.sh
#export PATH=/usr/local/gcc/bin:$PATH
source /etc/profile.d/gcc.sh
gcc --version
#gcc (GCC) 5.1.0

Export header file:

ln -sv /usr/local/gcc/include/ /usr/include/gcc
#"/usr/include/gcc" -> "/usr/local/gcc/include/"

Export library file:

vim /etc/ld.so.conf.d/gcc.conf
#/usr/local/gcc/lib64
ldconfig -v
ldconfig -p |grep gcc  //验证是否导出

At this point, GCC has also been installed.

Guess you like

Origin blog.csdn.net/qq_45467083/article/details/109533897