how to install and use a newer libc++ on older systems 10.7 to 10.12

Ken Cunningham ken.cunningham.webuse at gmail.com
Sun Jul 26 19:45:18 UTC 2020


You may have noticed that current software sometimes requires newer libc++ features than the installed system libc++.dylib version can support.

The libcxx port has the capability to install a newer libc++.dylib, currently the libc++ that matches llvm-5.0, which is quite recent in terms of OS version. 

The libc++.dylib for llvm-7.0 should be no problem either, I have that one working locally. There was an ABI change at llvm-8.0 that might or might not break installed libc++ software, so have to check that version more carefully. If so, there may be a way to build with the old ABI enabled I understand.

To allow the newer features to be accessed by clang, edit the "__config" file in the c++ includes for the clang version you're using, and disable Apple's availability tests that assume the system libc++.dylib is still installed.

WIth a new libc++.dylib, some software that is currently disabled or broken on older systems will build, eg. mysql8. So far I have tested this on 10.7.5.

$ port -v installed mysql8
The following ports are currently installed:
  mysql8 @8.0.21_0 (active) platform='darwin 11' archs='x86_64' date='2020-07-26T11:50:32-0700'


Here are the steps:

1. install the new system roots (doesn't actually install the software into /usr ):
sudo port -v -n upgrade --enforce-variants libcxx +replacemnt_libcxx +universal

2. save the old libc++:

(for some systems, you will have to disable SIP)

sudo cp /usr/lib/libc++.1.dylib /usr/lib/libc++.1.dylib.original
sudo cp /usr/lib/libc++abi.dylib /usr/lib/libc++abi.dylib.original

This also installs two cxxabi headers into /usr/linclude. These headers don't exist on 10.7.5, so don't need to be backed up it appears, but I haven't yet looked at all newer systems to see when they appeared, so you should check for them and back them up if they exist before you overwrite them:


3. Install the new libc++.

cd /
sudo tar xzvf /opt/local/var/system_roots/libcxx-5.0.1-4.tgz

$ ls -la /usr/lib/libc++*
-rwxr-xr-x  1 root  admin  2280984 26 Jul 09:12 /usr/lib/libc++.1.dylib
-rwxr-xr-x  1 root  wheel  1621344 26 Jul 09:25 /usr/lib/libc++.1.dylib.original
lrwxr-xr-x  1 root  admin       14 26 Jul 09:12 /usr/lib/libc++.dylib -> libc++.1.dylib
-rwxr-xr-x  1 root  admin   478220 26 Jul 09:12 /usr/lib/libc++abi.dylib
-rwxr-xr-x  1 root  wheel   153840 26 Jul 09:26 /usr/lib/libc++abi.dylib.original

$ ls -la /usr/include/*cxx*
-rwxr-xr-x  1 root  admin  2032 26 Jul 09:12 /usr/include/__cxxabi_config.h
-rwxr-xr-x  1 root  admin  6945 26 Jul 09:12 /usr/include/cxxabi.h


4. Then change macports-clang-N to ignore the Availability tests by editing the include/__config file for the clang version you're interested in using, for example for clang-9.0:

bbedit /opt/local/libexec/llvm-9.0/include/c++/v1/__config

and add this near the top:

// for MacPorts, our installed libcxx does not require Apple system Availability tests
#define _LIBCPP_DISABLE_AVAILABILITY


If you run into trouble, you can change the libc++ dylib back to the original.

Ken

 


More information about the macports-dev mailing list