building from source with libc++

Ken Cunningham ken.cunningham.webuse at
Wed Apr 19 16:22:27 UTC 2017

On 2017-04-19, at 1:05 AM, db wrote:
> $ clang --version
> Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
> Target: x86_64-apple-darwin12.6.0
> Thread model: posix
> Does this mean that I have 3.4 or something around that time of release?
> What exact port should then I install in order to have a modern compiler as you suggest? llvm-4.0 or clang-4.0?

Your system-installed clang is indeed something around 3.4. That's quite old.
For purposes of building current ports in macports, I would suggest you install clang-3.8. (see below about possible patch before you get started building it).

> And which configuration in macports.conf? I don't seem to find the right option in the guide,

You're right, that option is not listed there. It is listed in the LibCxxOnOlderSystems instructions, which is where I originally found it.
It looks like this, in macports.conf on my system.

default_compilers       macports-clang-3.8

>> 2. properly setting the standard c++ library.
> I'm now always building from source with libc++.
> If I change compiler, what are the odds that I run into some other oddities with the installed ports built with the default compiler?

If you followed the libcxx instructions properly (and you did), your macports c++ software will now be built against libc++, so that will be consistent. 

A remaining issue will be software, as mentioned, that doesn't specifically set the -stdlib on the build line during compilation. 

You can fix these ports by manually adding  -stdlib=libc++ to the CXXFLAGS and often LDFLAGS (as you described before), and/or you can change the default stdlib to libc++ in clang-3.8 (as I mentioned with my clang patch before), or alternatively Mojca's idea to add the stdlib spec to the CXX compiler environment variable would work as well, if that is implemented. 

The easiest of these for me was the clang-3.8 patch.

Even with all this, certain rare ports will still build with the system compiler (things built with xcode using xcodebuild, for example) and will still link against the default stdlib (libstdc++). Those builds could fail, but these ports are reasonably rare and if you hit these hiccups, you're probably hooped on older systems for SDK and hardware reasons anyway. 



More information about the macports-users mailing list