Invalid deployment target for -stdlib=libc++ on OSX 10.8
Asked Answered
V

2

5

I am compiling through node-gyp a Node.JS package written in C++. When I compile it I receive the following error: clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later). I'm running on OSX 10.8, and I have installed the XCode Command Line Tools. This is the file used by node-gyp to compile the package:

{
  "targets": [
    {
      "target_name": "package_name",

      'type': 'executable',

      'xcode_settings': {
        'OTHER_CFLAGS': [
          "-std=c++11",
          "-stdlib=libc++"
        ],
      },

      "sources": [ "package_src.cpp" ],
    }
  ]
}

Basically it specifies the target of the compilation, the type and the flags, as well as the sources.

Any idea on how I can solve this problem?

Vertu answered 13/2, 2014 at 10:56 Comment(1)
Not an answer to the question asked, but for Googlers arriving at this rather Google-juicey question after encountering this error message while trying to install something via a package manager: you can probably fix it with some environment variables. Either do MACOSX_DEPLOYMENT_TARGET=10.8 your_install_command to tell Clang to use a later deployment target, or install a real version of GCC (the gcc binary you've got is actually Clang), e.g. with brew install gcc, and tell make to use it via the CC and/or CXX environment variables - e.g. CC=gcc-9 CXX=g++-9 your_install_command.Gibber
V
2

I don't know what worked for you, @drewish, but this is how I got it to work:

{
  "targets": [
    {
      "target_name": "package_name",

      'type': 'executable',

      'xcode_settings': {
        'OTHER_CFLAGS': [
          "-std=c++11",
      "-stdlib=libc++",
      "-mmacosx-version-min=10.7"
        ],
      },

      "sources": [ "overcpu.cpp" ],
    }
  ]
}
Vertu answered 27/5, 2014 at 7:53 Comment(3)
Specifying "-mmacosx-version-min=10.7" ends up putting it in along with the "-mmacosx-version-min=10.5" that node-gyp inserts by default. My recollection is that the 10.5 ends up at the end and overrides the first one.Metaphase
May i know the location of this file?Mayolamayon
More info here @Mayolamayon github.com/nodejs/node-gyp/issues/1574Rabia
E
8

Whilst you got OS X 10.8 clang will try to build it so that it can be run on other older OS X versions too. Now since -stdlib=libc++ requires a minimum version of 10.7 it won't compile it unless you explicitly tell it that you'll use 10.7 (or higher) as the deployment target by specifying

'MACOSX_DEPLOYMENT_TARGET': '10.7'

inside the xcode_settings.

In your case the complete settings should look like:

{
  "targets": [
    {
      "target_name": "package_name",

      'type': 'executable',

      'xcode_settings': {
        'MACOSX_DEPLOYMENT_TARGET': '10.7',

        'OTHER_CFLAGS': [
          "-std=c++11",
          "-stdlib=libc++"
        ],
      },

      "sources": [ "package_src.cpp" ],
    }
  ]
}
Eyrir answered 26/5, 2014 at 19:30 Comment(1)
Ah yeah that works nicely. I was trying to pass '-mmacosx-version-min=10.7' in and it was concatenating it on, rather than replacing the existing 10.5 flag.Metaphase
V
2

I don't know what worked for you, @drewish, but this is how I got it to work:

{
  "targets": [
    {
      "target_name": "package_name",

      'type': 'executable',

      'xcode_settings': {
        'OTHER_CFLAGS': [
          "-std=c++11",
      "-stdlib=libc++",
      "-mmacosx-version-min=10.7"
        ],
      },

      "sources": [ "overcpu.cpp" ],
    }
  ]
}
Vertu answered 27/5, 2014 at 7:53 Comment(3)
Specifying "-mmacosx-version-min=10.7" ends up putting it in along with the "-mmacosx-version-min=10.5" that node-gyp inserts by default. My recollection is that the 10.5 ends up at the end and overrides the first one.Metaphase
May i know the location of this file?Mayolamayon
More info here @Mayolamayon github.com/nodejs/node-gyp/issues/1574Rabia

© 2022 - 2024 — McMap. All rights reserved.