How to build LLVM linked to libc++abi?


I sometimes build LLVM with a static libc++.a in MacOS, so that I use
the LLVM libc++ instead of the system-wide one. However, when doing
so, I always get link errors when building LLVM, because the build
system links with libc++.a, but not with libc++abi.a and so there are
quite a few missing symbols that the linker cannot find.

My workaround (which always seems to work) is to embed libc++abi
inside of libc++ (with libtool, for example), but that's a hack for
being in a hurry. BTW, note that I'm talking about building LLVM
itself, not my programs (when you build your programs it doesn't hurt
to add -lc++abi to your link line, but when building LLVM, how are
you supposed to do it? I've searched for a cleaner solution to this,
but couldn't find any.

Isn't there any LLVM build option for simply telling "hey! don't
forget to add -lc++abi whenever you link to libc++" ?



You can use LIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON CMake option to statically link libc++abi into libc++.a. You can also use LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY=OFF to disable statically linking libc++abi into (i.e. libc++abi will only be merged into libc++.a, not


Alternatively, you could rename libc++.a to libc++_internal.a and then create a linker script named libc++.a with the following content:

INPUT(libc++_internal.a libc++abi.a)

There’s no support to do so in CMake at the moment, but it’s something we’ve already discussed within Fuchsia as it’d be also useful for sanitizer runtimes so I might start a (separate) discussion about adding such support.

1 Like

Thanks a lot, but tried it and I get this:

CMake Error at projects/libcxx/CMakeLists.txt:361 (message):


Why is it not supported? If I manually embed libc++abi.a inside
libc++.a it seems to work.



See for reason why this is not supported. I have a change that removes this restriction, but I haven’t yet convinced libc++ maintainers to get an approval to merge this change.

Thanks a lot!! I'll apply your change and I'll report back (which,
BTW, ruins my goal of 7.0.0 being the first LLVM release I build on
MacOS without applying any patches).

And, honestly, I don't understand the rationale for not supporting
this on MacOS. If it's for the alleged reason of linking libc++ being
a mess in MacOS, then precisely for that very same reason some users
(like me) might want to statically link the whole thing (libc++,
libc++abi, and whatever) into their builds and forget the mess
forever. OTOH, if it's because you are supposed to use the libs
shipped with MacOS, then you should be supposed to be using Xcode
clang instead of building LLVM yourself, so LLVM should have a check
for refusing being built on MacOS.

I don't know if I can support you in some way for getting your change
admitted (as I'm not a LLVM developer), but I really look forward to
7.0.1 being the first release I build without applying patches :slight_smile:

In the meantime, I'm applying your change right now :slight_smile:

Thanks a lot!