10

I am trying to compile c++11 code on the Mac OS X using Qt Creator/qmake and I am getting the following error:

clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)

When I checked the compile command line, I noticed that it contains the -mmacosx-version-min=10.6 flag. I tried to update my .pro file as follows, but it seems that this is not taken into account:

QMAKE_CXXFLAGS += -std=c++11 -stdlib=libc++

macx {
    -mmacosx-version-min=10.7
}

Any suggestions would be helpful. Thanks!

BigONotation
  • 4,406
  • 5
  • 43
  • 72

2 Answers2

11

You can actually add that deployment target line QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6 to your QMake project file. You don't have to reinstall Qt.

One thing to keep in mind, though: if you build any other libraries that you include in your application bundle, make sure they're also compiled for backwards compatibility! In case it helps with any libraries, there's an equivalent CMake command as well, CMAKE_OSX_DEPLOYMENT TARGET.

rainbowgoblin
  • 1,221
  • 12
  • 28
10

OK found the solution after having looked at a similar question: QtCreator build system is broken after OSX upgrade

You can change the minimal Mac OS X target by updating the qmake.conf file for clang in your Qt installation (I am using Qt5.3). The file is located in the Qt installation directory at Qt/5.3/clang_64/mkspecs/macx-clang/qmake.conf The updated version is given below:

#
# qmake configuration for Clang on OS X
#

MAKEFILE_GENERATOR      = UNIX
CONFIG                 += app_bundle incremental global_init_link_order lib_version_first     plugin_no_soname
QMAKE_INCREMENTAL_STYLE = sublib

include(../common/macx.conf)
include(../common/gcc-base-mac.conf)
include(../common/clang.conf)
include(../common/clang-mac.conf)

#QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7

load(qt_config)

Note that I've commented out the default QMAKE_MACOSX_DEPLOYMENT_TARGET version providing with the Qt install.

Finally, you can also specify which sdk to use in your .pro file as follows:

macx {
    QMAKE_MAC_SDK = macosx10.9
}
Community
  • 1
  • 1
BigONotation
  • 4,406
  • 5
  • 43
  • 72
  • The fix is, then, to reinstall Qt. The installation process tweaks those files according to the platform. It is not unthinkable that a major OS version upgrade would break a development environment. – Kuba hasn't forgotten Monica Jun 16 '14 at 15:38
  • 1
    I don't think it has anything to do with reinstalling Qt. I am using the latest Qt 5.3 release. I think I read somewhere that when building Qt from source, you can specify the minimal deployment target for the Mac. This simply means that when the guys at Qt build the binaries, they specified Mac OS X 10.6 as the minimal deployment platform. – BigONotation Jun 18 '14 at 11:07
  • Since it obviously works for me and for lots of other people, I keep my assertion that it is the installation process that does the tweak. An installed version of Qt is not necessarily portable to a new major OS X revision. – Kuba hasn't forgotten Monica Jun 19 '14 at 17:50
  • Don't use relative paths in the things like `include(../common/macx.conf)`, these paths will be relative to the project location. Instead use absolute paths like for example `include(/Users/(username)/Qt/5.7/clang_64/mkspecs/common/macx.conf)`. – Donald Duck May 11 '17 at 17:30