Using libcxx and libcxxabi from a build tree on OS X

Hi All,

What is the correct way to use libcxx from a build dir on OS X?

I am running into the following issue:

  $ pwd
  /Users/meadori/Code/build/llvm

  $ cat test.cpp
  #include <exception>

  int main(void)
  {
     std::terminate();
     return 0;
  }
  $ ./bin/clang++ -L/Users/meadori/Code/build/llvm/lib test.cpp
  Undefined symbols for architecture x86_64:
    "std::terminate()", referenced from:
        _main in test-648ddf.o
  ld: symbol(s) not found for architecture x86_64
  clang-3.7: error: linker command failed with exit code 1 (use -v to
see invocation)

It would seem that the built libc++abi library isn't being found.

Have other encountered this?

I noticed that all the libcxx tests explicitly add -lc++abi.

What version of OSX are you running?

Have other encountered this?

I haven't but I'll try and reproduce today.

I noticed that all the libcxx tests explicitly add -lc++abi.

The libc++ tests also use -nodefaultlibs so we need to explicitly link
all of the libraries you would normally get.

/Eric

It looks like we are selecting the wrong libc++abi symbol list when
linking libc++. I'll try and get a fix in today.

I am using OS X 10.9.5 and CMake to build.

It isn't readily apparent how the symbols in the .exp files are chosen
or ordered. However, adding the following fixed my issue (I can apply
this if y'all deem it to be correct):

diff --git a/lib/libc++abi.exp b/lib/libc++abi.exp
index 87035b2..db965cd 100644
--- a/lib/libc++abi.exp
+++ b/lib/libc++abi.exp
@@ -157,3 +157,10 @@ __ZTIy
__ZTIx
__ZTIw
__ZTIv
+__ZSt13get_terminatev
+__ZSt13set_terminatePFvvE
+__ZSt14get_unexpectedv
+__ZSt14set_unexpectedPFvvE
+__ZSt15get_new_handlerv
+__ZSt15set_new_handlerPFvvE
+__ZSt9terminatev

Also, maybe I don't understand CMake well enough, but it doesn't
seem like LIBCXX_LIBCPPABI_VERSION is ever populated and that
ABI version 1 will always be chosen.

Also, maybe I don't understand CMake well enough, but it doesn't
seem like LIBCXX_LIBCPPABI_VERSION is ever populated and that
ABI version 1 will always be chosen.

That's the bug. It should be populated with "2" as far as I know.

Fix up for review as http://reviews.llvm.org/D7773.