Skip to content

Instantly share code, notes, and snippets.

@craigminihan
Last active September 21, 2023 12:47
Show Gist options
  • Star 88 You must be signed in to star a gist
  • Fork 23 You must be signed in to fork a gist
  • Save craigminihan/b23c06afd9073ec32e0c to your computer and use it in GitHub Desktop.
Save craigminihan/b23c06afd9073ec32e0c to your computer and use it in GitHub Desktop.
Build GCC 4.9.2 for C/C++ on CentOS 7
sudo yum install libmpc-devel mpfr-devel gmp-devel
cd ~/Downloads
curl ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-4.9.2/gcc-4.9.2.tar.bz2 -O
tar xvfj gcc-4.9.2.tar.bz2
cd gcc-4.9.2
./configure --disable-multilib --enable-languages=c,c++
make -j 4
make install
@ankitsablok89
Copy link

Also if you encounter any issues like configure error : no C compiler found on $PATH then you can run the following command on centOS/Redhat

yum groupinstall "Development tools"

awesome post, helped me a lot

@marquessbr
Copy link

ok, I can got it working, so how I can upgrade the cc compiler, because see below my console:

gcc --version

gcc (GCC) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

cc --version

cc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

thanks

@lucamosca1
Copy link

Hi there, is it working also on amazon linux for newer version of gcc compiler?

@mdisec
Copy link

mdisec commented Dec 5, 2016

Gimme one reason why you forced us to use -j 4 ? I've been sitting in front of computer for a hour even though I've 16 CPU 30gb RAM. :(

@ibrahimnegm2011
Copy link

Thanks a lot and for @ankitsablok89

@fahadmehar
Copy link

configure: error: Upgrade your compiler. GCC 4.7+ and Clang 3.2+ are known to work.

I wanted to install ZNC i am using Centos 6 64BIT... Please help me to fix this error. Thanks

@JBandassociate
Copy link

This is a bit silly, why not just --j. At least then no matter what hardware you have, make will use it to its capacity. unless doing other jobs, but this is a big job and will take hours with 4cpu.

@ElinhoPP
Copy link

[root@Talesofmidigard gcc-4.9.2]# make -j 4
make: *** No targets specified and no makefile found. Stop.
[root@Talesofmidigard gcc-4.9.2]#

@noglass
Copy link

noglass commented Oct 24, 2017

So I managed to install this successfully, and was compiling code fine, but to make the compiled code run, I had to add "/usr/local/lib64/" to the ls.so.conf. Everything was perfect! But then after a reboot gcc reverted back to version 4.8.5 again... Even after recompiling and reinstalling I cannot get 4.9.2 to work anymore. Any ideas?

@xuesongbj
Copy link

For Red Hat and Fedora based systems, run the following command:

[root@x.xx.x] # sudo yum install gmp gmp-devel mpfr mpfr-devel libmpc libmpc-devel

This will install the GNU multiple-precision (MP) libraries for integer, floating point, and complex numbers.

@abitofalchemy
Copy link

./configure command still complains:

checking whether /usr/local/bin/g++ supports C++14 features with -std=gnu++14... no
checking whether /usr/local/bin/g++ supports C++14 features with -std=gnu++1y... no
configure: error: *** A compiler with support for C++14 language features is required.```
I tried the above recommendations and can't get past this.

@mehdimoozeh
Copy link

thanks a lot

@u2tope
Copy link

u2tope commented Jun 14, 2018

Thanks. Save my day

But -j 4?... took hours for just 4 cpu.
I used --j instead like @JBandassociate indicated

@nikorose87
Copy link

Thanks!

@meetme2meat
Copy link

It takes infinity to build and install 😮

@klaud81
Copy link

klaud81 commented Oct 22, 2018

@leungi
Copy link

leungi commented Aug 26, 2019

Life saver!

Works on Red Hat Enterprise Linux Server release 7.3 (Maipo).

@leungi
Copy link

leungi commented Aug 26, 2019

@AjitDingankar
Copy link

ok, I can got it working, so how I can upgrade the cc compiler, because see below my console:

gcc --version

gcc (GCC) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

cc --version

cc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

thanks

I have the same problem for 5.2.0 on CentOS 7.6; after make install, gcc shows the new version but g++ shows 4.8.5!

Thanks,
Ajit

@leungi
Copy link

leungi commented Dec 7, 2019

check current path of gcc with which gcc, and then update symlink to your desired gcc path.

@AjitDingankar
Copy link

Thanks, but I didn't understand the instruction. My gcc already is the new one, it's the g++ that's the problem.

@AjitDingankar
Copy link

Looks like there was some problem with my original gcc, 4.8.5. I installed devtools-3 and rebuilt 5.2.0 with 4.9.2 from there. Now both gcc and g++ are the new version, 5.2.0.

Sorry about the noise, but thought this may help someone later, though I don't know exactly what the problem was in the first place.

@leungi
Copy link

leungi commented Dec 8, 2019

Thanks, but I didn't understand the instruction. My gcc already is the new one, it's the g++ that's the problem.

My bad.

What I meant was to check the different versions of g++/gcc that you have and create a symbolic link to the desired g++/gcc.

@quocnhat
Copy link

So how to uninstall gcc built by this method? Thank you

@DIMASIK1502
Copy link

Душевно

@zoncpp
Copy link

zoncpp commented Aug 22, 2021

Hi
maybe you need to run :
./contrib/download_prerequisites
before running "./configure ... " command

@edwincoronado
Copy link

I used make -j$(nproc) and it went much faster too.

@wellingtonf-souza
Copy link

wellingtonf-souza commented Mar 28, 2022

The command sequence below worked on my computer to update to version 7:
sudo yum -y install centos-release-scl
sudo yum -y install devtoolset-7
scl enable devtoolset-7 bash
gcc --version

@abdeljalil09
Copy link

abdeljalil09 commented Aug 9, 2022

The command sequence below worked on my computer to update to version 7: sudo yum -y install centos-release-scl sudo yum -y install devtoolset-7 scl enable devtoolset-7 bash gcc --version

this actually fixed an issue i had with node-canvas

npx node-pre-gyp rebuild -C ./node_modules/canvas

gcc version 4.8.5 was not working

@DevinXian
Copy link

Tremendous!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment