User Tools

Site Tools


info:clang

Clang References

Articles

Questions

Videos

Building with Clang

C++11

http://clang.llvm.org/cxx_status.html

Building with C++11 ("-std=c++0x" or "-std=c++11") seems to cause problems with the GCC libstdc++ headers. The status page links to patches that are supposed to make libstdc++-4.4 and libstdc++-4.7 work. I'm not sure if they work right on Linux, or if they break compilation with GCC. However, the 4.4 patch applies cleanly on RHEL6:

cd /usr/include/c++/4.4.4
sudo patch -p1 < ../libstdc++4.4-clang0x.patch

I made a backup of the 4.4.4 directory first. Even after the patch, I'm still getting errors when trying to compile as C++11. There are also errors coming from the Clang headers.

Building Clang

Setup

Downloaded LLVM 3.3 and related archives; extracted. I think this is right:

mv cfe-3.3.src llvm-3.3.src/tools/clang
mv compiler-rt-3.3.src llvm-3.3.src/projects/compiler-rt
mv clang-tools-extra-3.3.src llvm-3.3.src/tools/clang/tools/extra

Configure Options

I've built non-optimized for developing against Clang / libclang:

mkdir build33
cd build33
../llvm-3.3.src/configure --prefix=/opt/llvm33

Could add the --enable-optimized switch if using for compilation.

CMake Options

  • CLANG_BUILD_EXAMPLES=on
  • CLANG_VENDOR set to something appropriate to show who build it
  • CMAKE_BUILD_TYPE=Release
  • CMAKE_INSTALL_PREFIX=/opt/llvm31 (alter for version used)

Clang on RHEL5

  • No problem building Clang 3.1
    • Built the first time with CMake
  • Building programs doesn't work: apparently not compatible with the GCC 4.1.2 standard library
    • Try to figure out how to work with gcc44/libstdc++44 packages; not sure if with-gcc-toolchain option can work with this
  • Might be simpler to either:
    • Just use clang on RHEL6
    • Build a new copy of GCC 4.4+ and install it in e.g. /opt/gcc44 and use that with the with-gcc-toolchain/GCC_INSTALL_PREFIX option

GCC 4.4

Trying to get it to find the 4.4 standard library by using GCC 4.4 to build:

mkdir build-ac
cd build-ac
export CC=gcc44
export CXX=g++44
../configure --prefix=/opt/llvm31
time nice make

No luck.

Trying with CMake:

  • BUILD_SHARED_LIBS=true (update: one of the doc pages says this option is not recommended)
  • CMAKE_BUILD_TYPE=Release
  • CMAKE_INSTALL_PREFIX=/opt/llvm31
  • C_INCLUDE_DIRS=/usr/include/c++/4.4.4:/usr/include/c++/4.4.4/i386-redhat-linux6E:/usr/include/c++/4.4.4/backward:/usr/lib/gcc/i386-redhat-linux6E/4.4.4/include:/usr/include
  • GCC_INSTALL_PREFIX=/usr/include/c++/4.4.4

Messed up the first time (forgot to change the prefix) and had to remake.

Still not working. Without GCC_INSTALL_PREFIX (probably this one is not correct), it picks up the 4.1.2 headers; with it, it doesn't work for some other reason.

Related:

Clang on RHEL6

  • Trying Clang 3.0 first to try cmonster.
  • Building with CMake (Release, /opt/llvm30)
  • It compiles trivial programs, so hopefully it's working.
info/clang.txt · Last modified: 2013-07-19 04:35 by adminsam