2016年4月14日 星期四

Installing C++ 4.8.5 on CentOS 6.7

With yum on CentOS, the most updated gcc version are
gcc 4.1.2 for CentOS 5
gcc 4.4.7 for CentOS 6
gcc 4.8.5 for CentOS 7

What if you want to have higher version to run on CentOS 6? This article is going to tell you how to compile gcc on CentOS 6.7 which is the final version of CentOS.

First you are going to download CentOS 6.7 DVD1 ISO file.
http://centos.uhost.hk/6.7/isos/x86_64/CentOS-6.7-x86_64-bin-DVD1.iso

I used VMWare Workstation 12 Player to host the virtual machine. As it supports "Linux Easy Install", simply mount the ISO to a newly created VM, start it to enter user name and password. After 15 minutes, it will bring you to the Linux installed environment.


Install gcc compiler
First thing to to is to use terminal to install the most updated compiler. It will be used to compile the new compiler. Yes. gcc is compiled using its gcc compiler.
sudo yum install gcc-c++

Install glibc
sudo yum install -y gcc texinfo-tex flex zip libgcc.i686 glibc-devel.i686

Download gcc source code
wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz

Download mpc, mpfr, gmp package
tar zxf gcc-4.8.5.tar.gz
cd gcc-4.8.5
./contrib/download_prerequisites

Compile gcc
mkdir gcc-build-4.8.5
cd gcc-build-4.8.5
../configure --prefix=/usr
sudo make && make install

Check your gcc versions
gcc --version
gcc (GCC) 4.8.5
g++ --version
g++ (GCC) 4.8.5
which gcc
/usr/bin/gcc
which g++
/usr/bin/g++

After 2 hours of compilation, you will be able to see the below installed log.


Test the compilation:

cat >test.cc <<EOF
#include <iostream>
using namespace std;
int main() {
  cout << "Hello, World!" << endl;
  return 0;
}
EOF

g++ -o test.exe -g -Wall test.cc

./test.exe

Hello, World!

Check rpm installed
Because you are compiling gcc on your own, yum or rpm are unware of the new gcc version.
rpm -qa | grep gcc
gcc-4.4.7-16.el6.x86_64
libgcc-4.4.7-16.el6.x86_64
libgcc-4.4.7-16.el6.i686
gcc-c++-4.4.7-16.el6.x86_64

4 則留言:

  1. Hello,
    Thank you for that work, I install new gcc in my CentOS 6.8 but now the PC doesnt work, I think the rpm or yum as you said, do you know how to fix that?
    thank you

    回覆刪除
  2. Maybe you need to tell what "pc does not work" in detail.

    回覆刪除
  3. I cant log in, when I write username and password show a black screen and notification that I have problem, if there no solution tell me to desinstall this new version please.

    回覆刪除
  4. Probably your ~/bash_profile is in invalid format. Reinstalling the OS maybe a good solution.

    回覆刪除

2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...