This is guide howto build older GCC using newer one in Fedora. Currently GCC 12 for Fedora 38 using GCC 13. This is needed for running NVIDIA CUDA on Fedora 38.

Check video version of guide, howto build GCC 12 for Fedora 38 using GCC 13:

Build and Install GCC 12 on Fedora 38 using GCC 13

I use here sudo command for root user commands, if you don’t have/use sudo, then just use your root account directly.

1. Install Needed Packages to Build GCC 12

sudo dnf groupinstall "Development tools"

sudo dnf install mpfr-devel gmp-devel libmpc-devel \
zlib-devel glibc-devel.i686 glibc-devel isl-devel \
g++ gcc-gnat gcc-gdc libgphobos-static

2. Download GCC 12 and signature file

You can use any GCC mirror from GCC mirror sites.

wget https://bigsearcher.com/mirrors/gcc/releases/gcc-12.2.0/gcc-12.2.0.tar.xz \
https://bigsearcher.com/mirrors/gcc/releases/gcc-12.2.0/gcc-12.2.0.tar.xz.sig

3. Verify downloaded GCC package

$ gpg --verify gcc-12.2.0.tar.xz.sig gcc-12.2.0.tar.xz

gpg: Signature made Fri 19 Aug 2022 11:38:41 AM EEST
gpg:                using RSA key 7F74F97C103468EE5D750B583AB00996FC26A641
gpg: Can't check signature: No public key

$ gpg --recv-keys 7F74F97C103468EE5D750B583AB00996FC26A641

gpg: key 6EEB81F8981C74C7: public key "Richard Guenther <[email protected]>" imported
gpg: Total number processed: 1
gpg:               imported: 1

$ gpg --verify gcc-12.2.0.tar.xz.sig gcc-12.2.0.tar.xz

gpg: Signature made Fri 19 Aug 2022 11:38:41 AM EEST
gpg:                using RSA key 7F74F97C103468EE5D750B583AB00996FC26A641
gpg: Good signature from "Richard Guenther <[email protected]>" [unknown]
gpg:                 aka "Richard Guenther (Work) <[email protected]>" [unknown]
gpg:                 aka "Richard Guenther <[email protected]>" [unknown]
gpg:                 aka "Richard Guenther (GCC) <[email protected]>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 1397 5A70 E63C 361C 73AE  69EF 6EEB 81F8 981C 74C7
     Subkey fingerprint: 7F74 F97C 1034 68EE 5D75  0B58 3AB0 0996 FC26 A641

4. Extract GCC tar.xz

tar xvf gcc-12.2.0.tar.xz

5. Make build directory

cd gcc-12.2.0
mkdir build
cd build

6. Configure GCC 12

../configure --enable-bootstrap \
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto \
--prefix=/usr --program-suffix=-12.2 --mandir=/usr/share/man \
--infodir=/usr/share/info --enable-shared --enable-threads=posix \
--enable-checking=release --enable-multilib --with-system-zlib \
--enable-__cxa_atexit --disable-libunwind-exceptions \
--enable-gnu-unique-object --enable-linker-build-id \
--with-gcc-major-version-only --enable-libstdcxx-backtrace \
--with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu \
--enable-plugin --enable-initfini-array --with-isl \
--enable-offload-targets=nvptx-none --enable-offload-defaulted \
--enable-gnu-indirect-function --enable-cet --with-tune=generic \
--with-arch_32=i686 --build=x86_64-redhat-linux \
--with-build-config=bootstrap-lto --enable-link-serialization=1 \
--with-default-libstdcxx-abi=new --with-build-config=bootstrap-lto

7. Build GCC 12

Use -j parameter to build using multiple cores

make

## OR ##

make -j6

8. Install GCC 12 on Fedora 38

sudo make install

9. Check GCC 12 Installation

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/13/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-13.0.1-20230401/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-offload-defaulted --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.0.1 20230401 (Red Hat 13.0.1-0) (GCC)

$ gcc-12.2 -v
Using built-in specs.
COLLECT_GCC=gcc-12.2
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/12/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --program-suffix=-12.2 --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --enable-offload-defaulted --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1 --with-default-libstdcxx-abi=new --with-build-config=bootstrap-lto
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (GCC)

10. Uninstall GCC 12

cd build/gcc

sudo make uninstall

11. Support inttf