Problem

My Manjaro system’s default GCC installation version is GCC 14. I also have CUDA 12.1 and CUDA 12.5 installed concurrently, which require GCC 12 and GCC 13 respectively. Apparently, pacman and yay does not allow GCC 12 and GCC 13 to be installed at the same time (my system had GCC 12 and GCC 14 installed concurrently).

Downgrading system GCC 14 to GCC 13 is not an option, as it is the system default GCC and downgrading will break many applications’ lib dependencies.

The error I hit that is associated with mismatched CUDA and GCC versions is from the standard library complaining about undefined identifiers, for example:

/usr/include/stdlib.h(141): error: identifier "_Float32" is undefined

Solution

Method

  • Manually compile and install GCC-13 from source, then install it to a separate location (/usr/local/bin instead of /usr/bin).
  • Then, manually link the correct gcc and g++ binaries in the bin folder of the corresponding CUDA home folder.
    • Suppose GCC-13 was compiled and installed from source, then replace the symbolic links of gcc and g++ in /opt/cuda125/bin so that they point to the installed GCC-13 binaries instead of the system default GCC

Code

git clone https://gcc.gnu.org/git/gcc.git gcc-source
cd gcc-source/
git fetch --all --tags --prune
git checkout tags/<tag_name> -b <branch_name>
mkdir ../gcc-build
cd ../gcc-build
./../gcc-source/configure --prefix=<install location> --enable-languages=c,c++
make -j16
make install

Additional Notes

  • During gcc compile-from-source, if hitting problems similar to 'GLIBCXX_3.4.30' not found, try adding system libstdc++.so to LD_LIBRARY_PATH

References

CUDA Host Compiler Version Support

Official GCC install instructions

Stackoverflow Post for GCC-12 on Ubuntu