使用node.js Addon的node-gyp重建g ++构建错误

时间:2017-01-07 03:03:37

标签: c++ node.js g++ node-gyp

这是我的bindings.gyp文件:

{
  "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"
                  },
                }],
              ],
    }
  ]
}

运行时

sudo node-gyp rebuild

我收到这些错误:

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

从错误跟踪中,似乎很清楚我们使用的是g ++而不是gcc,而我的g ++版本是:

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

,是的,我在Ubuntu 16.04

有谁知道为什么会出现这个错误?

1 个答案:

答案 0 :(得分:1)

您有-std=c++1,这是一个错字,它应该是:-std=c++11

此外,-stdlib是一个clang选项(不是g ++)。对于g ++,总是使用libstdc ++。