This is a note to self, it contains the build process for
The process is not too different from any project that uses
Note: This post assumes that we are building
Obtain the source code
Clone the repository with
git clone git://gcc.gnu.org/git/gcc.git
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
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
cd gcc ./contrib/download_prerequisites
Build and install gcc
The next process is same as the build process for any other project that uses
INSTALLDIRenv variable for the installation directory path for gcc.
- Create a directory for building the project.
configurescuript for the project from that directory.
make installto install.
In this case,
- create a directory
configure script for gcc from that directory with config
configure --prefix=$INSTALLDIR --enable-languages=c,c++ --disable-multilib
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.