WebFaction
Community site: login faq

It's that time again.

How do I compile GCC 7.2 on CentOS 7?

(I'm interested in GCC 7 because it's the version included in Ubuntu 18.04 LTS).

asked 16 Nov, 08:00

ryans's gravatar image

ryans ♦♦
5.0k62856
accept rate: 43%


I would suggest running this in a screen session.

mkdir -p $HOME/bin $HOME/gcc/src $HOME/gcc/bin $HOME/gcc/lib
ln -s $HOME/gcc/lib $HOME/gcc/lib64

set +h    # disable shell hashing to ensure mid-installation binutils are used immediately

export PATH="$HOME/gcc/bin:$PATH"                       
export LD_LIBRARY_PATH="$HOME/gcc/lib:$LD_LIBRARY_PATH"

cd $HOME/gcc/src
wget 'http://www.netgull.com/gcc/releases/gcc-7.2.0/gcc-7.2.0.tar.xz'
tar -xf gcc-7.2.0.tar.xz
cd gcc-7.2.0
./contrib/download_prerequisites

mkdir build
cd build
../configure --prefix=$HOME/gcc --with-local-prefix=$HOME/gcc \
    --with-system-zlib --with-gnu-as --with-gnu-ld --enable-clocale=gnu \
    --enable-shared --enable-threads=posix --enable-__cxa_atexit \
    --disable-nls --disable-multilib

make            # Now go to sleep, as this takes ~4 hours.
make install    # Resist the temptation to "make -j8" because you'll probably
                # exceed your account memory quota...

############################################################
# Clean up & set Environment
############################################################
set -h
rm -rf $HOME/gcc/src
cd $HOME/gcc/bin && ln -s gcc cc

echo 'export PATH="$HOME/bin:$HOME/gcc/bin:$PATH"' >> $HOME/.bashrc
echo 'export CPPFLAGS="-I$HOME/include -I$HOME/gcc/include $CPPFLAGS"' >> $HOME/.bashrc
echo 'export LDFLAGS="-L$HOME/lib -L$HOME/gcc/lib $LDFLAGS"' >> $HOME/.bashrc
echo 'export LD_LIBRARY_PATH="$HOME/lib:$HOME/gcc/lib:$LD_LIBRARY_PATH"' >> $HOME/.bashrc

Now log out and back in again, and which gcc should show ~/gcc/bin/gcc.

permanent link
This answer is marked "community wiki".

answered 16 Nov, 08:04

ryans's gravatar image

ryans ♦♦
5.0k62856
accept rate: 43%

edited 16 Nov, 12:24

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×14

question asked: 16 Nov, 08:00

question was seen: 121 times

last updated: 16 Nov, 12:24

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2017 PARAGON INTERNET GROUP LIMITED
WEBFACTION IS A SERVICE OF PARAGON INTERNET GROUP LIMITED
REGISTERED IN ENGLAND AND WALES 7573953 - VAT REGISTRATION NUMBER 182147021
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM