This took me a good day of drilling into MacOSX, with a paucity of appropriate advice on the internet, which is why I’m writing this post.
-mmacosx-version-min compiler flag
The first hint is to use the -mmacosx-version-min compiler flag, which takes values like 10.9 (for Mavericks) or 10.12 (for Sierra). If you are compiling everything from self-contained source code, it suffices to add this compiler flag to your CFLAGS variable, and build away. I discovered by experimentation that Mavericks was about the earliest OSX that support the C++11 standard library.
Checking the minimum version of an executable or library
Use otool -l executable or library and then look for the tag LC_VERSION_MIN_MACOSX
MACOSX_DEPLOYMENT_TARGET environment variable
If you don’t specify the above compiler flag, then the clang compiler will examine the value of the MACOSX_DEPLOYMENT_TARGET environment variable, and use that the target of the compiler. This is useful as a way of setting the deployment target without editing a bunch of files (say you’re compiling a bunch of 3rd party libraries).
If the environment variable not set, then the current OSX release version is used.
The problem with MacPorts is that it overrides the MACOSX_DEPLOYMENT_TARGET and sets it to your current machine’s value.
After a lot of browsing of the TCL scripts that MacPorts used, I found that you can add it as a configuration option to /opt/local/etc/macports/macports.conf
macosx_deployment_target 10.9 buildfromsource always
The second option is required to prevent macports downloading prebuilt binary packages.
Final tip is if you have already built some packages before setting the above options, then you can rebuild the ports via
port upgrade --force installed
Follow these topics: Uncategorized