Get this book -> Problems on Array: For Interviews and Competitive Programming
In this article, we have presented the steps to build any version of GCC from source and install it.
Table of contents:
- Step 1: Get source code of GCC
- Step 2: Configure GCC
- Step 3: Build and Install GCC
- Complete steps
Step 1: Get source code of GCC
Clone the source code of GCC using this command:
git clone https://github.com/gcc-mirror/gcc.git
cd gcc
Checkout to the version you need. If we need the version 12.2.0, then the command is as follows:
git checkout releases/gcc-12.2.0
Skip the above step if you want to build the latest version of GCC.
Step 2: Configure GCC
To configure the GCC to build the desired features, use the following command:
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-12.2.0/configure --prefix=$HOME/GCC-12.2.0 --enable-languages=c,c++,fortran,go
If you want to build the compiler for only C programming language, the last command is updated as follows:
$PWD/../gcc-12.2.0/configure --prefix=$HOME/GCC-12.2.0 --enable-languages=c
Step 3: Build and Install GCC
To build GCC from source after configuration, use the following command:
make -j
make install
Once done, restart the session and check the version of GCC using the following command:
gcc --version
Complete steps
Following is the complete compiled steps to build GCC version 12.2.0 from source:
git clone https://github.com/gcc-mirror/gcc.git
cd gcc
git checkout releases/gcc-12.2.0
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-12.2.0/configure --prefix=$HOME/GCC-12.2.0 --enable-languages=c,c++,fortran,go
make -j
make install
With these steps in this article at OpenGenus, you must be able to build and install any version of GCC.