×

Search anything:

Build GCC from source [GCC v12.2.0]

C++

Internship at OpenGenus

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:

  1. Step 1: Get source code of GCC
  2. Step 2: Configure GCC
  3. Step 3: Build and Install GCC
  4. 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.

Geoffrey Ziskovin

Geoffrey Ziskovin

Geoffrey Ziskovin is an American Software Developer and Author with an experience of over 30 years. He started his career with Haskell and has interviewed over 700 candidates for Fortune 500 companies

Read More

Improved & Reviewed by:


OpenGenus Foundation OpenGenus Foundation
Build GCC from source [GCC v12.2.0]
Share this