Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to select a particular gcc-toolchain in clang?

Tags:

c++

linux

gcc

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 force clang to use a different gcc installation, say 5.4.1 ?

i tried to call clang with --gcc-toolchain="/usr/lib/gcc/x86_64-linux-gnu/5.4.1" but without success.

like image 434
Gaetano Avatar asked Jan 31 '17 16:01

Gaetano


People also ask

Does clang depend on GCC?

Clang depends on libgcc and crt object files. They can be built and installed independently, of course, but there is no canonical way of doing so.

Does clang define __ GNUC __?

(GNU C is a language, GCC is a compiler for that language.Clang defines __GNUC__ / __GNUC_MINOR__ / __GNUC_PATCHLEVEL__ according to the version of gcc that it claims full compatibility with.

Is GCC a toolchain?

GCC is a toolchain that compiles code, links it with any library dependencies, converts that code to assembly, and then prepares executable files.

What is compile GCC toolchain?

Therefore, the GCC toolchain is a set of applications and libraries to compile programs written in several languages. For instance, for the C and C++ languages, that includes tools like: cpp Preprocessor. gcc C compiler. g++ C++ compiler.


1 Answers

An valid path for --gcc-toolchain is apparently "/usr" as clang seem to look for gcc in

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

so as a workaround you can trick clang to use a particular version by creating a filesystem with overlay-fs or symlinking a 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 maybe there is a better way by instructing clang to pick the version via a flag...

like image 160
Gaetano Avatar answered Oct 12 '22 22:10

Gaetano