Clang会自动选择版本最高的gcc版本:
$ 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
我怎么能强迫clang使用不同的gcc安装,比如说5.4.1?
我试图用--gcc-toolchain =“/ usr / lib / gcc / x86_64-linux-gnu / 5.4.1”调用clang,但没有成功。
答案 0 :(得分:5)
--gcc-toolchain的有效路径显然是“/ usr”,因为clang似乎在寻找gcc
$PREFIX/{include|lib}/gcc/$PLATFORM/$VERSION/*
所以作为一种解决方法,您可以通过使用overlay-fs创建文件系统或者通过符号链接仅包含一个文件夹的文件夹结构来欺骗使用特定版本
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
然而,通过指示clang通过旗帜选择版本可能有更好的方法...