For target triples where GCC is the primary compiler, Clang detects a GCC installation and uses files from it (mainly libstdc++, crtbeginS.o
and similar crt files). When GCC installations of multiple versions exist, there is no way specifying the desired version (other than hard coding -isystem
/etc by oneself).
I have a patch ⚙ D133329 [Driver] Add --gcc-install-dir= which will allow to specify the GCC version:
# Debian and many derivatives
clang++ --gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/12 -m32 a.cc
clang++ --gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/11 a.cc
# Gentoo
clang++ --gcc-install-dir=/usr/lib/gcc/x86_64-gentoo-linux-musl/11.2.0 a.cc
See https://github.com/llvm/llvm-project/issues/57570 for a use case simplifying Gentoo gcc-config.
--gcc-toolchain=
was added to replace cmake GCC_INSTALL_PREFIX
(which has a long history in Clang).
The option specifies a directory where lib/gcc{,-cross}/$triple/$version
can be found.
I think --gcc-toolchain=
and GCC_INSTALL_PREFIX
are not useful and should be deprecated.
Most users don’t specify the option. When the option is specified as /usr
, it is like unspecified.
When the option specifieds a GCC installation in a nonstandard place, that place is typically a sysroot.
When --sysroot=
is specified, Clang auto detects lib/gcc{,-cross}/$triple/$version
in $sysroot/usr
and $sysroot
, and --gcc-toolchain=
is not needed.
When the GCC installation is not contained in the sysroot, typically the user wants to fix the GCC version as well.
The new --gcc-install-dir=
can be used instead.
--gcc-toolchain=
has been around for some time there are some use cases, so it cannot be removed anytime soon.
But GCC_INSTALL_PREFIX
seems unused and should be removed.