How to select specific gcc-toolchain in clang?

Clang automatically selects the gcc version with the highest version:

$ clang++ -v main.cpp clang version 3.8.1-12 (tags/RELEASE_381/final) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.4 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.1 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.2.0 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.0.1 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.4 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.1 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.2.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.0.1 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.0.1 

how can i get clang to use another gcc installation, say 5.4.1?

I tried calling clang with -gcc-toolchain = "/usr/lib/gcc/x86_64-linux-gnu/5.4.1" but without success.

+6
source share
1 answer

The valid path for the -gcc-toolchain is apparently "/ usr", since clang seems to be looking for gcc in

 $PREFIX/{include|lib}/gcc/$PLATFORM/$VERSION/* 

as a workaround you can trick clang to use a specific version by creating a file system with overlay-fs or a symbolic folder structure containing only one folder

 mkdir $MYTOOLCHAIN cd $MYTOOLCHAIN ln -s /usr/include include #for headerfiles ln -s /usr/bin bin #for tools like ld mkdir -p lib/gcc/x86_64-linux-gnu/ #clang will deduce what to select cd lib/gcc/x86_64-linux-gnu/ #link the toolchain we want here ln -s /usr/lib/gcc/x86_64-linux-gnu/$VERSION $VERSION #usage: clang++ --gcc-toolchain=$MYTOOLCHAIN main.cpp 

however, there may be a better way instructing clang to select a version using a flag ...

+4
source

Source: https://habr.com/ru/post/1014599/


All Articles