Trouble building Clang on CentOS 6

Hi,
I’m having trouble building Clang on CentOS 6 and am hoping someone here can help. I followed the instructions on this website:

http://btorpey.github.io/blog/2015/01/02/building-clang/

I’m using GCC 6.3.0 and Python 2.7.13, both also built from source using these options:

-DCMAKE_C_COMPILER=<gcc-6.3.0>/redhat6/bin/gcc
-DCMAKE_CXX_COMPILER=<gcc-6.3.0>/redhat6/bin/g++
-DCMAKE_CXX_LINK_FLAGS=‘-L<gcc-6.3.0>/redhat6/lib64 -Wl,-rpath,<gcc-6.3.0>/redhat6/lib64’
-DLLVM_ENABLE_ASSERTIONS=ON
-DCMAKE_BUILD_TYPE=Release
-DLLVM_TARGETS_TO_BUILD=X86
-DGCC_INSTALL_PREFIX=<gcc-6.3.0>/redhat6
-DPYTHON_EXECUTABLE:FILEPATH=<python-2.7.13>/redhat6/bin/python
-DCMAKE_INSTALL_PREFIX=<clang-4.0.1>/redhat6

The errors I’m seeing look like this (I used -j32):

[ 4%] Building CXX object lib/TableGen/CMakeFiles/LLVMTableGen.dir/Main.cpp.o
[ 4%] Building CXX object lib/Option/CMakeFiles/LLVMOption.dir/OptTable.cpp.o
[ 6%] Building C object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/absvdi2.c.o
[ 6%] Building CXX object projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.x86_64.dir/sanitizer_coverage_mapping_libcdep.cc.o
Scanning dependencies of target LLVMSupport
g++: fatal error: no input files
compilation terminated.
make[2]: *** [bin/llvm-PerfectShuffle] Error 1
make[1]: *** [utils/PerfectShuffle/CMakeFiles/llvm-PerfectShuffle.dir/all] Error 2

[ 28%] Linking CXX static library …/libLLVMSupport.a
[ 28%] Built target LLVMSupport
[ 28%] Built target RTAsan.x86_64
make: *** [all] Error 2
make install
[ 0%] Built target LLVMDemangle
[ 3%] Built target LLVMSupport
[ 3%] Built target LLVMTableGen
[ 4%] Built target obj.llvm-tblgen
Scanning dependencies of target llvm-tblgen
[ 4%] Linking CXX executable …/…/bin/llvm-tblgen
g++: fatal error: no input files
compilation terminated.
make[2]: *** [bin/llvm-tblgen] Error 1
make[1]: *** [utils/TableGen/CMakeFiles/llvm-tblgen.dir/all] Error 2
make: *** [all] Error 2

Any thoughts about what else I need to do?

Thanks,
Uri

Hi Uri,

Hi,
I'm having trouble building Clang on CentOS 6 and am hoping someone here can
help. I followed the instructions on this website:

Building clang on RedHat - Confessions of a Wall Street Programmer

Seems a bit old, why not Clang - Getting Started

I'm using GCC 6.3.0 and Python 2.7.13, both also built from source using
these options:

-DCMAKE_C_COMPILER=<gcc-6.3.0>/redhat6/bin/gcc
-DCMAKE_CXX_COMPILER=<gcc-6.3.0>/redhat6/bin/g++
-DCMAKE_CXX_LINK_FLAGS='-L<gcc-6.3.0>/redhat6/lib64
-Wl,-rpath,<gcc-6.3.0>/redhat6/lib64'
-DLLVM_ENABLE_ASSERTIONS=ON
-DCMAKE_BUILD_TYPE=Release
-DLLVM_TARGETS_TO_BUILD=X86
-DGCC_INSTALL_PREFIX=<gcc-6.3.0>/redhat6
-DPYTHON_EXECUTABLE:FILEPATH=<python-2.7.13>/redhat6/bin/python
-DCMAKE_INSTALL_PREFIX=<clang-4.0.1>/redhat6

The errors I'm seeing look like this (I used -j32):

[ 4%] Building CXX object
lib/TableGen/CMakeFiles/LLVMTableGen.dir/Main.cpp.o
[ 4%] Building CXX object
lib/Option/CMakeFiles/LLVMOption.dir/OptTable.cpp.o
[ 6%] Building C object
projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/absvdi2.c.o
[ 6%] Building CXX object
projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.x86_64.dir/sanitizer_coverage_mapping_libcdep.cc.o
Scanning dependencies of target LLVMSupport
g++: fatal error: no input files
compilation terminated.
make[2]: *** [bin/llvm-PerfectShuffle] Error 1
make[1]: *** [utils/PerfectShuffle/CMakeFiles/llvm-PerfectShuffle.dir/all]
Error 2

(snip)

Any thoughts about what else I need to do?

For debugging purposes, build with

make VERBOSE=1

This would print the actual compiler invocation; the we'll have a
better chance figuring out what went wrong.

Csaba

Hi Csaba,
I started with the instructions on the LLVM website. The problem is that CentOS 6 does not meet the build requirements, shown here:

http://llvm.org/docs/GettingStarted.html#requirements

I built the required versions of software but the instructions don’t cover how to utilize them.

Anyway, I compiled again with VERBOSE and discovered the problem is missing LibraryDependencies.inc. I specified python27 with a CMake variable and added it to my PATH but it still didn’t solve the problem:

make[2]: Nothing to be done for projects/compiler-rt/lib/builtins/CMakeFiles/builtins.dir/build'. make[2]: Leaving directory <clang-4.0.1>/src/build/llvm-4.0.1-redhat6’
[ 36%] Built target builtins
<llvm-4.0.1>/tools/llvm-config/llvm-config.cpp:47:35: fatal error: LibraryDependencies.inc: No such file or directory
#include “LibraryDependencies.inc”
^
compilation terminated.
make[2]: *** [tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o] Error 1
make[2]: Leaving directory `<clang-4.0.1>/src/build/llvm-4.0.1-redhat6’
make[1]: *** [tools/llvm-config/CMakeFiles/llvm-config.dir/all] Error 2

How can I move past this error? Despite setting LD_LIBRARY_PATH and CMAKE_CXX_LINK_FLAGS as indicated in the instructions above, I also still seem to be getting GLIBC errors too :frowning:

Thanks,
Uri

I built the latest Git on CentOS 6 two days ago, but I use upgraded CMake, GCC, Python and other things. So there is nothing fundamentally wrong with CentOS other than the built-in packages it comes with are too old.

I recall CMake does something idiotic wherein it prefers /usr/bin/python over which python, which you have to manually override with -DPYTHON_EXECUTABLE=which python, or at least that is what I archived in my successful build script.
https://github.com/jeffhammond/HPCInfo/blob/master/buildscripts/llvm-git.sh#L95

Jeff

I get the same error using your build script :frowning:

46%] Copying clang’s cuda_wrappers/algorithm…
[ 46%] Copying clang’s cuda_wrappers/new…
[ 46%] Copying clang’s cuda_wrappers/complex…
[ 46%] Building arm_neon.h…
…/…/…/…/bin/clang-tblgen: /usr/lib64/libstdc++.so.6: version GLIBCXX_3.4.20' not found (required by ../../../../bin/clang-tblgen) ../../../../bin/clang-tblgen: /usr/lib64/libstdc++.so.6: version CXXABI_1.3.9’ not found (required by …/…/…/…/bin/clang-tblgen)
…/…/…/…/bin/clang-tblgen: /usr/lib64/libstdc++.so.6: version GLIBCXX_3.4.14' not found (required by ../../../../bin/clang-tblgen) ../../../../bin/clang-tblgen: /usr/lib64/libstdc++.so.6: version GLIBCXX_3.4.19’ not found (required by …/…/…/…/bin/clang-tblgen)
…/…/…/…/bin/clang-tblgen: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21’ not found (required by …/…/…/…/bin/clang-tblgen)
make[2]: *** [tools/clang/lib/Headers/arm_neon.h.tmp] Error 1
make[2]: *** Waiting for unfinished jobs…
make[1]: *** [tools/clang/lib/Headers/CMakeFiles/clang-headers.dir/all] Error 2
[ 46%] Linking CXX executable …/…/bin/not
[ 46%] Built target not
[ 46%] Linking CXX executable …/…/bin/llvm-cxxfilt
[ 46%] Linking CXX executable …/…/bin/llvm-mcmarkup
[ 46%] Built target llvm-cxxfilt

My CMake, FCC, and Python builds were from source, not the package manager. I’m using CentOS 6.7 btw.

I think there’s a clue in the error message here, given the reference to /usr/lib64. I noticed that spaces in arguments were getting dropped by CMake in commands. You don’t have the linker option CMAKE_CXX_LINK_FLAGS specified from the build instructions but even if you did, the latter half of the option is truncated.

Perhaps set LD_LIBRARY_PATH so clang-tblgen can find the correct version of libstdc++.so.

Not sure this will help, but I had a similar problem of using a compiler in a no-standard location, and used this cmake command. The only real difference from what you are doing is the use of CMAKE_EXE_LINKER_FLAGS.

cmake \
-GNinja \
-DCMAKE_C_COMPILER=/opt/gcc-7/bin/gcc \
-DCMAKE_CXX_COMPILER=/opt/gcc-7/bin/g++ \
-DGCC_INSTALL_PREFIX=/opt/gcc-7 \
-DCMAKE_EXE_LINKER_FLAGS=“-Xlinker -R/opt/gcc-7/lib64 -L/opt/gcc-7/lib64” \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_PARALLEL_LINK_JOBS=1

/usr/lib64/libstdc++.so.6 indicates that you need to set LD_LIBRARY_PATH to point to the toolchain you installed.

Best,

Jeff

Setting LD_LIBRARY_PATH seems to solve the problem but then leaves a runtime dependency. The variable needs to be set when the executable is called as well. The instructions provided a CMake variable that was supposed to solve this problem (CMAKE_CXX_LINK_FLAGS)… only it doesn’t seem to work.

I figured it out: “-DCMAKE_CXX_FLAGS=-static-libstdc++”. The link flags don’t appear to be necessary. I think the CMake variable changed for it too, now CMAKE_EXE_LINKER_FLAGS.

I’d happily update the documentation but I’ve not contributed to this project before. Should I try or ask one of you to do it?