12

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.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
John Dibling
  • 99,718
  • 31
  • 186
  • 324
  • `$HOME/toolchains/bin/g++ --version` gives you 4.8.2 does not mean that the system sees this installation. Simple `g++ --version` should result in 4.8.2. I think you have already tried adding the install path to PATH variable, or not ? If yes, is the order correct? – shrm May 15 '14 at 08:27
  • @mishr: But I specified `--with-gcc-toolchain=/root/toolchains/` on `configure`'s command line? – John Dibling May 15 '14 at 12:24
  • Note to readers: Doing `export PATH=/root/toolchains/bin/:$PATH` *did* allow me to run `configure` cleanly, but I'd rather not do this everywhere, and it seems to imply that `--with-gcc-toolchain` doesn't do what I thought. – John Dibling May 15 '14 at 12:44

2 Answers2

7

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.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • Aha, I see. `--with-gcc-toolchain` did *not* do what I thought it did. Am I correct in assuming that even if I do `export` the path, I still need to specifiy the `with-gcc-toolchain` option? – John Dibling May 15 '14 at 12:50
  • @John As far as I understand, using that option will hardcode the libstdc++ paths from your GCC 4.8.2 install into the Clang binary, which means it can use that C++ library without extra options. So yes, I think that will be useful. To prevent this kind of trouble, I suggest using libc++ instead. – rubenvb May 15 '14 at 12:53
  • Thanks for your suggestion. I'll read through the docs again so that I can understand it. :) – John Dibling May 15 '14 at 12:54
0

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
kjell-e
  • 1
  • 1