使用特定的gcc工具链从源代码构建clang [英] build clang from source using specific gcc toolchain
问题描述
我正在从源代码构建clang,但是所使用的gcc 7.2构建并不存在于正常位置.我希望生成的clang++
二进制文件默认情况下使用此工具链.我尝试这样做:
I'm building clang from source, but using a gcc 7.2 build that doesn't live in the normal spot. I want the resulting clang++
binary to use this toolchain by default. I tried to do:
$ export GCC_PREFIX=/path/to/gcc/7.2
$ mkdir -p build
$ cd build
$ cmake -G Ninja -DCMAKE_C_COMPILER=${GCC_PREFIX}/bin/gcc \
-DCMAKE_CXX_COMPILER=${GCC_PREFIX}/bin/g++ \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_TARGETS_TO_BUILD=X86 ..
但是生成的构建只是在/usr/include/c++/4.8.5
中查找标准库包含的内容,而不是像我想要的那样包含/path/to/gcc/7.2/include
(并且,如路径所示,4.8.5有点旧了).有没有一种方法可以构建clang,使得生成的二进制文件将在我想要的路径中查找其包含目录?
But the resulting build just looks in /usr/include/c++/4.8.5
for standard library includes instead of /path/to/gcc/7.2/include
like I wanted it to (and, as the path suggests, 4.8.5 is a bit old). Is there a way to build clang such that the resulting binary will search the path I want for its include directory?
注意,我知道我使用--gcc-toolchain=${GCC_PREFIX}
运行生成的 binary .那个有效.我要做的是将其构建到二进制文件中,因此不必每次都键入它.
Note, I know I run the produced binary with --gcc-toolchain=${GCC_PREFIX}
. That works. What I want to do is build that into the binary so I don't have to type it every time.
推荐答案
刚刚找到了这个.正确的方法是提供GCC_INSTALL_PREFIX
:
Just found this. The correct way to do this is to provide GCC_INSTALL_PREFIX
:
$ cmake -G Ninja -DCMAKE_C_COMPILER=${GCC_PREFIX}/bin/gcc \
-DCMAKE_CXX_COMPILER=${GCC_PREFIX}/bin/g++ \
-DGCC_INSTALL_PREFIX=${GCC_PREFIX} \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_TARGETS_TO_BUILD=X86 ..
那做对了.根据需要,生成的clang二进制文件的行为就像您提供了--gcc-toolchain=${GCC_PREFIX}
一样.
That does the right thing. The resulting clang binary behaves as if you provided --gcc-toolchain=${GCC_PREFIX}
, as desired.
这篇关于使用特定的gcc工具链从源代码构建clang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!