building from source with libc++

Ken Cunningham ken.cunningham.webuse at gmail.com
Wed Apr 19 22:13:41 UTC 2017


> On Apr 19, 2017, at 2:10 PM, db <iamsudo at gmail.com> wrote:
> 
> Are the other steps described in the LibcxxOnOlderSystems instructions for 10.6 not necessary for 10.8?

10.8 already has /usr/lib/libc++.dylib installed, so you don’t need to go through the bootstrapping hoops to get that as you do on 10.6. 

Just setting your "cxx_stdlib libc++" and "buildfromsource always" in macports.conf will be enough.

I think the Lion and Mountain Lion LibCxxOnOlderSystems instructions could probably suggest/recommend installing and setting the default compiler to something newer, but I defer to the gurus here. They support people of all skill levels, and if you’re changing your default compiler, you should have a pretty good idea what and why you’re doing that.

> 
>> 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.
> 
> If I understood correctly Apple's clang natively does what stock clang needs to be patched for.

It’s an important concept to have cold, to understand what’s going on (and fix things when they might not work).

clang (macports-installed versions) looks at the build line it’s asked to compile. If it sees -stdlib=something specified on the build line, it uses that. No problems. Presumably you set it correctly. It uses the last one it finds on the build line, if it finds more than one.

However, if clang doesn’t see -stdlib specified on the build line, as shipped it will automatically add -stdlib=libstdc++ on < 10.9, and -stdlib=libc++ on 10.9+.

Although this is usually what you might want, IF you’ve modified your system as you and I are doing to force the use of libc++ on <10.9, this will be the wrong behaviour, and you will get link errors when building some or most macports software. In short, clang has no idea that we would want to use libc++ even though we are on <10.9 — that’s not the way the system shipped...

So the fix is to either make sure there is always a -stdlib=libc++ placed on the build line (purest, but frequently enough is not there), OR to modify the default behaviour of clang on these modified systems to teach it to add -stdlib=libc++ instead of -stdlib=libstdc++ even on < 10.9. This turns out to be quite easy.


The few times I tried sending -stdlib=libc++ to the system installed clang version when building with xcode on 10.6, it just generated an error saying I had used the wrong stdlib …. so I don’t think you can override that behaviour. I haven’t explored that much.


> 
> Both 3.8 and 3.9 are at rev 3 but I'd rather assume I could patch llvm portfile manually and use your patch file 999.

The patch should work just the same unless that one file has been significantly changed (doubt it). If so, the patch phase of the port build will error out.

The patch for clang-3.8 and the patch for clang-3.9 are different, in case you didn’t notice. I’d stick with clang-3.8 for now - it works fine to get you started. The clang-3.9 patch is also in the same general repo, but in the llvm-3.9/files folder.


You can also make the change manually if you want to look yourself and be completely sure you know what is happening. It’s quite easy to do.

Run ‘sudo port patch clang-3.8’ with the current unmodified macports clang-3.8 portfile, then find and open the file mentioned in the 999 patch (cd `port work clang-3.8` will get you started there), scroll down to the part of interest, change it yourself manually to be sure you did what you wanted to do, and then ‘sudo port -v install clang-3.8’ it and it will just keep on building from there with your changes.

Best,

Ken


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macports.org/pipermail/macports-users/attachments/20170419/fedbec8d/attachment.html>


More information about the macports-users mailing list