This is a note to self, it contains the build process for gcc
for c
and
c++
frontends.
The process is not too different from any project that uses autotools
.
Note: This post assumes that we are building gcc
on fedora
for x86_64
architecture.
Obtain the source code
Clone the repository with
git clone git://gcc.gnu.org/git/gcc.git
dependencies
You will need to install following packages in order to build gcc
from source.
mpfr-devel
: Development files for the MPFR library.The MPFR library is a C library for multiple-precision floating-point computations with correct rounding. Source: https://www.mpfr.org/
gmp-devel
: Development tools for the GNU MP arbitrary precision library.GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers. Source: https://gmplib.org/
libmpc-devel
: Headers and shared development libraries for MPC.GNU MPC is a C library for the arithmetic of complex numbers with arbitrarily high precision and correct rounding of the result. It extends the principles of the IEEE-754 standard for fixed precision real floating point numbers to complex numbers, providing well-defined semantics for every operation. At the same time, speed of operation at high precision is a major design goal. Source: http://www.multiprecision.org/mpc/
zlib-devel
: Header files and libraries for Zlib development.A Massively Spiffy Yet Delicately Unobtrusive Compression Library (Also Free, Not to Mention Unencumbered by Patents) Source: https://zlib.net/
glibc-devel
: Object files for development using standard C libraries.The GNU C Library project provides the core libraries for the GNU system and GNU/Linux systems, as well as many other systems that use Linux as the kernel. These libraries provide critical APIs including ISO C11, POSIX.1-2008, BSD, OS-specific APIs and more. These APIs include such foundational facilities as open, read, write, malloc, printf, getaddrinfo, dlopen, pthread_create, crypt, login, exit and more. Source: https://www.gnu.org/software/libc/
To install these dependencies using dnf
sudo dnf groupinstall "Development tools"
sudo dnf install mpfr-devel gmp-devel libmpc-devel zlib-devel glibc-devel
Or you can use the script contrib/download_prerequisites
from the gcc
repository itself.
cd gcc
./contrib/download_prerequisites
Build and install gcc
The next process is same as the build process for any other project that uses
autotools
.
- Create
INSTALLDIR
env variable for the installation directory path for gcc. - Create a directory for building the project.
- Run
configure
scuript for the project from that directory. - Run
make
to build. - Run
make install
to install.
In this case,
- create a directory gcc-build
.
- run configure
script for gcc from that directory with config
configure --prefix=$INSTALLDIR --enable-languages=c,c++ --disable-multilib
- run make
- run make install
export INSTALLDIR=gcc-install
cd ..
mkdir gcc-build
mkdir gcc-install
cd gcc-build
../gcc/configure --prefix=$INSTALLDIR --enable-languages=c,c++ --disable-multilib
make -j$(nproc)
make install
Once this is done, you can add $INSTALLDIR/bin
to your $PATH
and use gcc
that we just built from the source.