简体   繁体   中英

g++ build errors with node-gyp rebuild for Node.js Addon

Here is my bindings.gyp file:

{
  "targets": [
    {
      "target_name": "hello",
      "sources": [ "hello.cpp" ],
      "include_dirs": [
        "<!(node -e \"require('nan')\")"
      ],
       "cflags" : [ "-std=c++1", "-stdlib=libc++" ],
              "conditions": [
                [ "OS!='win'", {
                  "cflags+": [ "-std=c++11" ],
                  "cflags_c+": [ "-std=c++11" ],
                  "cflags_cc+": [ "-std=c++11" ],
                }],
                [ "OS=='mac'", {
                  "xcode_settings": {
                    "OTHER_CPLUSPLUSFLAGS" : [ "-std=c++11", "-stdlib=libc++" ],
                    "OTHER_LDFLAGS": [ "-stdlib=libc++" ],
                    "MACOSX_DEPLOYMENT_TARGET": "10.7"
                  },
                }],
              ],
    }
  ]
}

when running

sudo node-gyp rebuild

I get these errors:

make: Entering directory '/home/oleg/WebstormProjects/oresoftware/replace-line/build'
  CXX(target) Release/obj.target/hello/hello.o
g++: error: unrecognized command line option ‘-std=c++1’
g++: error: unrecognized command line option ‘-stdlib=libc++’
hello.target.mk:106: recipe for target 'Release/obj.target/hello/hello.o' failed

from the error trace, seems clear that we are using g++ not gcc, and my g++ version is:

gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 

and yep I am on Ubuntu 16.04

Does anyone know why this error is occurring?

You have -std=c++1 , which is a typo, it should be: -std=c++11 .

Also, -stdlib is a clang option (not g++). For g++ libstdc++ is always used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM