node-gyp 忽略 (c++17) cflag
node-gyp ignores (c++17) cflag
我尝试用这个配置和构建一个 node.js C++ 插件
binding.gyp 文件:
{
"targets": [
{
"target_name": "addon",
"sources": [ "addon.cpp" ],
"cflags": [
"-std=c++17"
]
}
]
}
但是当我 运行 node-gyp configure
和 node-gype rebuild
我总是收到类似
的消息
warning: ‘if constexpr’ only available with -std=c++17 or -std=gnu++17
构建也失败了,因为我真的依赖这些c++17特性。我做错了什么?
使用"cflags_cc"
(而不是"cflags"
)有效。
这解决了问题。
cflags cflags_cc 对我不起作用,但使用 VCCLCompilerTool 中的设置它可以工作(在 Windows 上):
{
'targets': [
{
'target_name': 'test-napi-native',
'sources': [ 'src/test_napi.cc' ],
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")"],
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
'cflags': [ '-fno-exceptions' ],
'cflags_cc': [ '-fno-exceptions' ],
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '10.7'
},
'msvs_settings': {
'VCCLCompilerTool': { "ExceptionHandling": 1, 'AdditionalOptions': [ '-std:c++17' ] }
}
}
]
}
我尝试用这个配置和构建一个 node.js C++ 插件 binding.gyp 文件:
{
"targets": [
{
"target_name": "addon",
"sources": [ "addon.cpp" ],
"cflags": [
"-std=c++17"
]
}
]
}
但是当我 运行 node-gyp configure
和 node-gype rebuild
我总是收到类似
warning: ‘if constexpr’ only available with -std=c++17 or -std=gnu++17
构建也失败了,因为我真的依赖这些c++17特性。我做错了什么?
使用"cflags_cc"
(而不是"cflags"
)有效。
这解决了问题。
cflags cflags_cc 对我不起作用,但使用 VCCLCompilerTool 中的设置它可以工作(在 Windows 上):
{
'targets': [
{
'target_name': 'test-napi-native',
'sources': [ 'src/test_napi.cc' ],
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")"],
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
'cflags': [ '-fno-exceptions' ],
'cflags_cc': [ '-fno-exceptions' ],
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '10.7'
},
'msvs_settings': {
'VCCLCompilerTool': { "ExceptionHandling": 1, 'AdditionalOptions': [ '-std:c++17' ] }
}
}
]
}