Node.js 插件的 node-gyp 重建 g++ 构建错误
g++ build errors with node-gyp rebuild for Node.js Addon
这是我的 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
有谁知道为什么会出现这个错误?
你有-std=c++1
,打错了,应该是:-std=c++11
.
此外,-stdlib
是一个 clang 选项(不是 g++)。对于 g++,始终使用 libstdc++。
这是我的 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
有谁知道为什么会出现这个错误?
你有-std=c++1
,打错了,应该是:-std=c++11
.
此外,-stdlib
是一个 clang 选项(不是 g++)。对于 g++,始终使用 libstdc++。