Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to build clang and libc++ together (bootstrap)

I would like to build a recent clang + llvm + libc++. I'm currently on a system (based on CentOS 6.6) where I can't easily get binary packages of clang, but where I can set up a GCC recent enough for building clang (for example 4.9), by setting some environment variables.

I'd like my version of clang to be

  • Portable, that is no hardcoded paths (e.g. using -rpath $ORIGIN)
  • Neither dependent on the system gcc nor the imported gcc 4.9 (that is, their C/C++ runtimes)
  • In particular, neither the compilers, the compiler-as-a-library libclang.so, nor programs built with the new compiler should depend on libstdc++, but they should use the newly built libc++.

I can do this, but it involves putting clang, llvm, libc++, libc++abi (and things I might have forgotten) in one tree, building clang from one build directory, then setting a lot of flags blindly and building it again from a second build directory.

Is there another proper way of bootstrapping clang with libc++? I believe there must be, since the official binaries of llvm & clang are self-sufficient as I described above.

like image 894
jdm Avatar asked Sep 18 '15 08:09

jdm


1 Answers

I've been curious about this myself and don't think there is a proper, "blessed" way of bootstraping clang with li bc++.

In my experience, clang installed from repositories depends on libstdc++, and so does clang installed from binary distributions available at http://www.llvm.org/releases/download.html#3.7.0 (I've tried the one for Ubuntu 14.04). A few differences between repo clang and that from llvm.org:

  • I haven't seen a repo clang with libc++; I had to build it separately. Clang from llvm.org does come with libc+ +.
  • The llvm.org clang appears to have the library location, relative to where it lives, hardcoded; same goes for some headers (!) that live in the lib directory.

Considering that clang from repositories and llvm.org depends on libstdc++, I would say that there is no proper wa y of getting rid of that dependency, at least not on Linux systems I've played with, which include Ubuntu, Amazon Linux, CentOS, and Fedora.

Having said this, however, I find that even using clang dependent on libstdc++ allows one to produce programs that depend on libc++ instead of libstdc++. Even though it is possible to build a clang+llvm setup that does not itself depend on libstdc++, as you have found already, I don't think it's necessary to jump through all those hoops.

In case you find it helpful, I have a brief article on this at http://www.omniprog.info/clang_no_gcc.html (also see this)

I'm still experimenting with all this and will update this answer if I come across something interesting.

like image 61
Anatoli P Avatar answered Oct 04 '22 21:10

Anatoli P