How does centos7 install gcc5.4

Due to the need to use cilk plus and std=c++14 , I decided to upgrade the compiler.

The basic tutorial is as follows:

1. Download the GCC source code :


 wget
ftp://mirrors.kernel.org/gnu/gcc/gcc-5.4.0/gcc-5.4.0.tar.gz

2. Unzip:


 tar -zxvf
gcc-5.4.0.tar.gz

3. Download the dependencies required for compilation:

  cd
gcc-5.4.0 // Enter the unpacked gcc folder
 
./contrib/download_prerequisites
                  // download dependencies

 cd ..    
                      // return to upper directory

4. Create a compilation output directory:


 mkdir
gcc-build-5.4.0

5. Enter the output directory, execute the following command, and generate the makefile :

  cd
gcc-build-5.4.0

 ../gcc-5.4.0/configure –prefix=/usr/local --enable-checking=release --enable-languages=c,c++ --disable-multilib
-- The prefix is ​​very important and must be filled in.

6. Compile:

 
make -j4

The next step is to wait, the whole process takes about 40 minutes. PS : It is best not to do anything else during the compilation process. The CPU is fully loaded during the whole process. If it is terminated inexplicably, there will be a lot of trouble later.

7. Installation:

After compiling, we can execute the installation:

 
make install

The above are all writing routine operations, and the following are the pits encountered,

braced spec is invalid

specific questions%:sanitize(xxx)错误,非法。

这个问题google了一下午,发现解决方法就只有一种,那就是将specs中的%sanitize(xxx)统统改为fsanitize=xxx


还有就是安装完成后,我在我笔记本上输入gcc -v提示的是5.4。但是centos7这个奇葩,还要设置别的东西,要记得建立软连接:

sudo ln -s /usr/local/gcc-4.5.0/bin/gcc /usr/bin/gcc
  sudo ln -s /usr/local/gcc-4.5.0/bin/g++ /usr/bin/g++

References:

1. http://blog.sina.com.cn/s/blog_73cb8ab50102uwq1.html gcc installation problemInstall multiple versions of gcc under Linux

2.https://gcc.gnu.org/ml/gcc-help/2014-12/msg00028.html Fatal error during GCC 4.9.2 build

3. https://blog.csdn.net/u012027907/article/details/45459025 Linux compile and install GCC-5.1.0



 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325046731&siteId=291194637