How should I best to install and use libc++ from svn on OS X

625 views Asked by At

Due to a bug in the release version of clang, I need to compile and install it from SVN trunk. I figured I might as well also compile SVN trunk libc++ at the same time. I am running an up to date OS X 10.10.1, with macports installed libs and binaries where needed.

I've managed to compile clang and libc++ using the commands at the end of this post, installing them into $HOME/usr/local/. Compiling my program with $HOME/usr/local/bin/clang++ works fine. However, when running the executables, the version of libc++ used is the system version. (As seen by setting export DYLD_PRINT_LIBRARIES=1 before running it.)

I then tried export DYLD_LIBRARY_PATH=$HOME/usr/local/lib which makes all executables use the new version of libc++. However, it seems that some other executables do not like this change in which libc++ is being used. For example, ls fails with the following errors:

dyld: Symbol not found: __ZTISt9bad_alloc
  Referenced from: /usr/lib/libutil.dylib
  Expected in: /Users/d97sjan/usr/local/lib/libc++.1.dylib
in /usr/lib/libutil.dylib
Trace/BPT trap: 5

Is this a bug in libc++ or dyld, or am I just crazy to believe that swapping out libc++ globally by setting DYLD_LIBRARY_PATH is feasible?

I can make it work by running my executable with DYLD_LIBRARY_PATH=$HOME/usr/local/lib a.out, but I'd rather have a cleaner solution if possible.

Any ideas or comments of how to make it work, or rather how it should be done?

Edit: After comment by "The Paramagnetic Croissant" on that it's not feasible to swap out libc++ for other binaries [although it works for some]. Can I at compile time add some hints in my binary to dyld so that it loads the correct libc++? Or should I just stick with the standard libc++ and just compile my own clang? What's anyone's advice?

Code for compiling and installing clang and libc++

# From http://clang.llvm.org/get_started.html
svn co -q http://llvm.org/svn/llvm-project/llvm/trunk llvm
svn co -q http://llvm.org/svn/llvm-project/cfe/trunk llvm/tools/clang
svn co -q http://llvm.org/svn/llvm-project/clang-tools-extra/trunk llvm/tools/clang/tools/extra
svn co -q http://llvm.org/svn/llvm-project/compiler-rt/trunk llvm/projects/compiler-rt
#From http://libcxx.llvm.org/
svn co -q http://llvm.org/svn/llvm-project/libcxx/trunk llvm/projects/libcxx

mkdir llvm_build_release
cd llvm_build_release
cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/usr/local -DLLVM_TARGETS_TO_BUILD=host ../llvm
ninja
ninja install
1

There are 1 answers

3
Jeremy Huddleston Sequoia On

If your issue is with the runtime and you want to do this, I suggest you use MacPorts as I added support for this into the libcxx and libcxxabi ports last month.

Specifically, install the libcxx and libcxxabi ports with the +replacemnt_libcxx variant set at build time, and we'll build you a root that you can install in /opt/local/var/system_roots. To install the root, use darwinup:

  sudo darwinup install /opt/local/var/system_roots/libcxxabi-*
  sudo darwinup install /opt/local/var/system_roots/libcxx-*

As this will replace a system library, be prepared to boot into target disk mode and uninstall the roots if something goes wrong:

  sudo darwinup -p /Volumes/TargetDisk list
  sudo darwinup -p /Volumes/TargetDisk uninstall <id for libcxx root>
  sudo darwinup -p /Volumes/TargetDisk uninstall <id for libcxxabi root>

Also note that the versions of libcxx and libcxxabi are the ones from llvm-3.5.0. I am not sure the exact differences between that version and what is in OS X 10.10.1, and I am not sure if it contains the fix you need or not. If it doesn't, please file an issue in MacPorts trac, and I'll cherry pick it in for you.


If your issue is with with the STL, then again, I suggest you use MacPorts and just install the clang ports you want:

sudo port -v -s install clang-3.4
sudo port -v -s install clang-3.5
sudo port -v -s install clang-3.6

You can then use the clang++-mp-3.4 (or 3.5/3.6) compiler from the command line or use 'sudo port select clang' to set what you want to be default for 'clang++'