Compiling GCC 15.1

During the May Day holiday, I saw that GCC released a new version, so I decided to experience the std after the module refactoring by compiling GCC myself.Environment: Ubuntu 24.041. Download the source codeYou can use the Tsinghua mirror:git clone https://mirrors.tuna.tsinghua.edu.cn/git/gcc.git [Here you can specify the desired folder name]2. Download the necessary dependenciesEnter the source code directory and execute./contrib/download_prerequisitesAfter success, it will display:Compiling GCC 15.13. Download some related libraries for compilationgcc g++ make flex4. Configuration file

./configure --prefix=/home/szh/workspace/soft/gcc-15.1 --enable-bootstrap --enable-checking=release --disable-multilib

This will generate a makefile5. Compilemake -j106. Installmake installAfter success:Compiling GCC 15.17. Configure environment variablesAdd the following to ~/.bashrc

export PATH=/home/szh/workspace/soft/gcc-15.1/bin:$PATH
export LD_LIBRARY_PATH=/home/szh/workspace/soft/gcc-15.1/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/szh/workspace/soft/gcc-15.1/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/szh/workspace/soft/gcc-15.1/libexec:$LD_LIBRARY_PATH
export INCLUDE=/home/szh/workspace/soft/gcc-15.1/include:$INCLUDE

Compiling GCC 15.1source ~/.bashrcOpen a new terminal and test:Compiling GCC 15.1Test the new standard library:Write the code:

import std;auto main()-> int {    std::println("GCC15.1");    return 0;}

Compilation command, two-stage compilation:

g++ -std=c++23 -fmodules-ts -c -fmodule-only -fsearch-include-path bits/std.cc

Generated: gcm.cacheCompiling GCC 15.1

g++ -std=c++23 -fmodules-ts main.cpp -o main

Generate the executable programRun result:Compiling GCC 15.1After waiting for 20 years, I finally got such an easy Hello World! C++ is becoming more like Python.

Leave a Comment