Now running C++ programs requires an increased version of the G++ compiler. The default G++ version of centos7 is 4.8.5. You need to upgrade the G++ version to a higher version. The following uses G++12.0.1 as an example.
1. Download the GCC package method - GCC-12.1.0
Method 2:
Command: wget (Linux file download command)
Format: wget+space+parameter+file path
wget [OPTION]… [URL]…
Example: wget http://mirrors.ustc.edu.cn/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz
Parameter: -c endpoint resume function
Example: wget -c http://mirrors.ustc.edu.cn/gnu/gcc/gcc-4.1.2/gcc-4.1.2.tar.bz2
(Note: cannot be under root; http: cannot use https:)
After downloading the GCC package, upload it to the linux server.
2. Unzip the compressed package
Command: tar ( Linux decompression/compression command)
Format: tar+space+parameter group+document
Parameters: Independent parameters: -c: Create compressed archive; -x: Decompress; -t: View content; -r: Append files to the end of the compressed archive; -u: Update files in the original compressed package
(Only one can be used)
Optional parameters: -z: with gzip attribute; -j: with bz2 attribute; -Z: with compress attribute; -v: display all processes; -O: unpack the file to standard output
The following parameter -f is required: -f: Use the file name. Remember, this parameter is the last parameter, and can only be followed by the file name.
例:tar zxvf gcc-8.2.0.tar.gz
3. Download GCC files and dependencies
Enter the unzipped package:
Run the script: ./contrib/download_prerequisites
successfully
Note: 1. This step will take a long time if the internet speed is slow.
2. If bzip2 is not installed on the server, an error will be reported. Please install bzip2:
yum -y install bzip2
4. Generate makefile compilation file
In the decompressed cabbage noodles, create the compilation directory: mkdir gcc-build-12.1.0
cd gcc-build-12.1.0
../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
Result: creatingMakefile successful
5. Compile
Compile according to the Linux virtual setting core number: make -j4 (j4 means 4 cores, option)
Note: Compilation requires patience! It will take a little longer, so please wait patiently if no error is reported.
6. Install gcc
Installation command: sudo make install
7. Check the gcc version: g++ -v / gcc -v