52

I often need to target Mac OS X versions that are older than the one I'm currently running. As I prefer to work with a bash shell and Makefiles, I do not use Xcode. Apple explicitly supports targeting older OS X versions, but I've always been confused by the redundancy of the two configuration steps that are usually taken to target older platforms:

  1. gcc is started using --macosx-version-min:

    gcc --mmacosx-version-min=10.6 ....
    
  2. The MACOSX_DEPLOYMENT_TARGET environment variable is set to the desired platform, e.g.

    export MACOSX_DEPLOYMENT_TARGET=10.6
    

When trying to figure out the actual difference between the two by searching, you'll come up with different answers. Some people say that they do exactly the same, so it's only necessary to use one of the two. However, there are also voices which say that it's necessary to do both: start gcc with --macosx-version-min and set the environment variable.

Are these two things exactly the same? Is it only necessary to use one of the two but not both? Is there some official documentation available somewhere? Apple mentions MACOSX_DEPLOYMENT_TARGET but doesn't mention --macosx-version-min at all, even though it seems to be much more common.

1
  • 1
    As far as I can tell, both methods work on macOS until 10.14 (Mojave). Looking at some open source projects which broke for me, it seems as if the build environment in 10.15 (Catalina) and newer only supports MACOSX_DEPLOYMENT_TARGET. (I haven't tested myself on 10.15 or newer.)
    – Joel Purra
    Sep 29, 2021 at 17:52

2 Answers 2

57

The man pages of gcc on Mac OS X say that they're synonymous:

-mmacosx-version-min=version
The earliest version of MacOS X that this executable will run on is
version.  Typical values of version include 10.1, 10.2, and 10.3.9.

This value can also be set with the MACOSX_DEPLOYMENT_TARGET environment
variable.  If both the command-line option is specified and the
environment variable is set, the command-line option will take precedence.
1
  • 1
    After Apple switched to Clang, the GCC flag is "less synonymous" than using MACOSX_DEPLOYMENT_TARGET ;)
    – Joel Purra
    Sep 29, 2021 at 17:44
6

Keep in mind, that apple changed default compiler to clang. Currently clang tries to translate gcc flags to his own. But it doesn't cover 100%. So it might happen that -mmacosx-version-min will stop working one day.

3
  • 5
    Yeah, looks like now is the day, i tried and --mmacosx-version-min is not working for me anymore, and MACOSX_DEPLOYMENT_TARGET is working now
    – jerson
    Feb 14, 2021 at 23:05
  • @jerson would this be a valid flag then in cmake config ? ``` set(MACOSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment version" FORCE)```
    – Dariusz
    Feb 2, 2022 at 11:53
  • 2
    @jerson That option still works for me with the latest Xcode 14.2 command line tools. However it starts with one dash, not two.
    – Mark Adler
    Jan 9 at 3:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.