9

Edit/Update/Note: Just let clang use libstdc++. Has been working really well for me so far.

===============================

In the past I have been able to succeed by doing something with cmake, but just now I discovered a buildit script inside the lib directory of the http://llvm.org/svn/llvm-project/libcxx/trunk project tree.

This buildit script appears to not make use of libsupc++ which is what the cmake approach that I took earlier used. For instance, this guide shows one cmake incantation to produce a makefile for libc++, which will be able to take care of compiling and installation.

My question is what is the difference between these different ways to produce the LLVM-libc++ and which one should be used? Will they behave differently?

The buildit script does not appear to provide any help for installation. Are there directions anywhere for how to properly install the library? With my previous libc++ built with cmake, I had to always add -lc++ to the linker flags (and the path with -L), which is not necessary in my OS X makefiles.

Steven Lu
  • 41,389
  • 58
  • 210
  • 364
  • I read up some more on just what `libsupc++` is, and apparently it is a subset of GCC's `libc++`. The `buildit` script appears to link `libc++`, so I guess nothing is surprising here, and maybe I just need to tweak some `cmake` flags to get a more streamlined install. Still, I'd appreciate some general explanations by someone who knows more than I do about LLVM. – Steven Lu Jul 29 '13 at 07:12
  • you mean `libsupc++` provides some ABI-related (and other) functionality for GCC's `libstdc++`. – rubenvb Jul 29 '13 at 08:48

1 Answers1

3

The libc++ website has a nice overview of the possible ways to build libc++.

I suggest using CMake + libc++abi.

Also see the Arch Linux User Repository build script, which uses the buildit script. I installed libc++ from that and used it with the Arch Linux Clang package succesfully by using

clang++ -std=c++11 -stdlib=libc++ -lc++abi
Steven Lu
  • 41,389
  • 58
  • 210
  • 364
rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • 3
    Well, I'm on CentOS 6.4 which makes it slightly harder than usual to get stuff working because many items are .... old. I had to include the extra paths `/usr/include/c++/4.4.4;/usr/include/c++/4.4.4/x86_64-redhat-linux` in addition to the 4.4.7 dirs, and also copy `cxxabi-forced.h` (which was in `4.4.4/`) to `bits/cxxabi_forced.h`, before the `cmake` call succeeds. This is too painful! This will go in my machine init script, so I'll be fine for a little while. But someone needs to come up with something less painful because this is `cmake` not doing its one and only job. – Steven Lu Aug 28 '13 at 17:12
  • 1
    I also had to change within the `cxxabi.h` the `#include` from `cxxabi-forced.h` to `bits/cxxabi_forced.h` to get the libc++.so `make` call to succeed. – Steven Lu Aug 28 '13 at 17:29
  • 1
    This no longer works (with SVN libc++). With the resulting libc++.so, any attempt to compile with `-std=c++0x -stdlib=libc++` results in a mysterious `undefined reference to \`vtable for std::nested_exception'` – Steven Lu Nov 25 '13 at 22:30
  • @Steven: did you build with libc++abi or libsupc++? In either case, try linking the one you need manually. Unfortunately, I cannot check SVN libc++ right now, so I can only suggest contacting the cfe-dev mailing list about this. I did update my answer to reflect the current libc++abi preference, which is used in the AUR package. – rubenvb Nov 26 '13 at 09:50
  • What GCC does Arch Linux come with (presumably used to build clang with)? – Steven Lu Nov 26 '13 at 14:12
  • @StevenLu, Did you ever find a solution to the `vtable for std::nested_exception' problem? I see it too on CentOS 6.5, and I have to revert back to the libcxx from the 3.3 release to have something functional. Google search doesn't turn up anything useful. – nilweed Jul 30 '14 at 18:16
  • I may have, but it's been too long since I've run my automated clang build script for CentOS... Not since 6.5 got released. One of these days I'll get back to testing it to see if it will work on 6.5. – Steven Lu Jul 30 '14 at 22:07
  • I had success on CentOS 6.5 (i686) by running buildit in libcxx, copying the lib to /usr/lib, and making symbolic links there to the lib with truncated version numbers. I then did the same with libcxxabi. `clang++ -std=c++11 -stdlib=libc++ -lc++abi` seems to work fine. – Jim Hunziker Aug 20 '14 at 17:45
  • I would suggest not to do work with bleeding edge compilers on distros like CentOS. Fedora makes a whole lot better sense -- code your stuff on your Fedora box, compile it there, and then distribute binaries to the CentOS boxes, or something... I would imagine `sudo yum install clang` or some such will take care of it. Still, [I am now dealing](http://stackoverflow.com/questions/25920130) with the same original issue in this question (how the hell to get libc++ built), but on OS X now. You'd think it'd be less complicated... but it might actually be easier to develop clang plugins on Linux... – Steven Lu Sep 18 '14 at 19:13
  • @Steven Compiling on Fedora will link it to a newer glibc than is available on CentOS, which makes the resulting binary unusable. As for building libc++ on Mac OS X... I thought XCode came with it already built. And there's always CMake and/or the `buildit` script. – rubenvb Sep 18 '14 at 20:06
  • Yeah, the Xcode clang is specifically patched to disable plugins and the sort of things I specifically am now working on. The nice thing is Xcode does let me swap out for the new clang that I build, so I can actually get the Xcode GUI working alongside the plugins I make, but I have to get it working first! – Steven Lu Sep 18 '14 at 20:13