Question

I am running on an RHEL 6.x box, which of course has GCC 4.4 installed. I wish to have LLVM running on this machine. In order to do so, I must compile it from source. In order to do that, I need a more modern version of GCC.

So, following the instructions, I have built GCC 4.8.2:

[snip]
% $PWD/../gcc-4.8.2/configure --prefix=$HOME/toolchains --enable-languages=c,c++
% make -j$(nproc)
% make install

I'm logged in as root, so $HOME/toolchains resolves to /root/toolchains.

After satisfying prerequisites for LLVM, I'm ready to configure and build LLVM.

root@dev06 /root/llvm-build # ~/llvm/configure --enable-optimized --prefix=$HOME/toolchains/ --with-gcc-toolchain=/root/toolchains/
checking for clang... no
[snip]
checking target architecture... x86_64
checking whether GCC is new enough... no
configure: error:
The selected GCC C++ compiler is not new enough to build LLVM. Please upgrade
to GCC 4.7. You may pass --disable-compiler-version-checks to configure to
bypass these sanity checks.
root@dev06 /root/llvm-build # 

configure thinks I'm using GCC 4.4 still, even though I passed --with-gcc-toolchain=/root/toolchains/ to configure1. Let's make sure that I installed 4.8.2 properly.

root@dev06 /root/llvm-build # $HOME/toolchains/bin/g++ --version
g++ (GCC) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

How do I convince configure to use the GCC I have at /root/toolchains?


1: I have tried a number of variations of the path I specify in --with-gcc-toolchain, inclding /root/toolchain/bin, /root/toolchain/bin/g++, etc.

Was it helpful?

Solution

As you have discovered, the proper way to resolve this is by adding your custom toolchain to PATH. This is not a systemwide change, and is limited to your shell session. Alternatively, you can configure with:

../llvm/configure CXX=$HOME/toolchains/bin/g++

and similar options documented in configure's --help output.

The option --with-gcc-toolchain only tells the built Clang where to look for a C++ standard library and headers, it has nothing to do with the LLVM/Clang build process. I strongly suggest to also build and install libc++ and libc++abi and use those with your new Clang instead.

OTHER TIPS

The LLVM project no longer supports building with configure & make.

I specified c, c++ and fortran compiler in the variables CC, CXX and FC.

export CC=/path/to/gcc
export CXX=/path/to/g++
export FC=/path/to/gfortran

cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/opt/clang ../llvm-4.0.0
make
make install
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top