-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any way to use C++17 on MSBuild? #1662
Comments
Add the following to your binding.gyp: 'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': [ '-std:c++17', ],
},
}, |
Failed
|
replace |
Verbose output (from npm or node-gyp):Traceback (most recent call last): File "E:\NPM_PREFIX\node_modules\prebuild\node_modules\node-gyp\gyp\gyp_main.py", line 16, in sys.exit(gyp.script_main()) File "E:\NPM_PREFIX\node_modules\prebuild\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 545, in script_main return main(sys.argv[1:]) File "E:\NPM_PREFIX\node_modules\prebuild\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 538, in main return gyp_main(args) File "E:\NPM_PREFIX\node_modules\prebuild\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 514, in gyp_main options.duplicate_basename_check) File "E:\NPM_PREFIX\node_modules\prebuild\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 130, in Load params['parallel'], params['root_targets']) File "E:\NPM_PREFIX\node_modules\prebuild\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 2783, in Load variables, includes, depth, check, True) File "E:\NPM_PREFIX\node_modules\prebuild\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 425, in LoadTargetBuildFile build_file_data, PHASE_EARLY, variables, build_file_path) File "E:\NPM_PREFIX\node_modules\prebuild\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 1293, in ProcessVariablesAndConditionsInDict build_file, key) File "E:\NPM_PREFIX\node_modules\prebuild\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 1303, in ProcessVariablesAndConditionsInDict ' for ' + key) TypeError: Unknown type set for AdditionalOptions while trying to load binding.gypi had changed binding.gyp as you said, but it does not work |
please try and use Refael's exact syntax:
note the placement of |
@rvagg still not working |
This is a full working example for anyone who also has this problem: {
"targets": [
{
"target_name": "proj",
"sources": [ "src/proj.cc" ],
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")"
],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
"cflags": [ "-fno-exceptions" ],
"cflags_cc": [ "-fno-exceptions", "-std=c++17" ],
"conditions": [
['OS=="mac"', {
"xcode_settings": {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
"CLANG_CXX_LIBRARY": "libc++",
"CLANG_CXX_LANGUAGE_STANDARD":"c++17",
'MACOSX_DEPLOYMENT_TARGET': '10.14'
}
}],
['OS=="win"', {
"msvs_settings": {
"VCCLCompilerTool": {
"AdditionalOptions": [ "-std:c++17", ],
},
},
}]
]
}
]
}
|
The solutions above didn't work for me - the only way I could get it to work was using
It thows off some warnings, but it configures the project as it should and compiles |
Yes. |
That's strange. None of the given solutions sets the standard in the sln file for the analysis. But it works for the build. |
see .vcxproj file? |
If anyone need solution irrespective of node-gyp use can use cmake... You can do this using cmake-js node package. |
Node-gyp should be able to do this automatically, but it does not. CMake easily does it by using. set(CMAKE_CXX_STANDARD 17)
Thanks! I need to transfer to cmake-js. Too many problems with node-gyp. It does not solve anything for me as I have to manually maintain compiler flags for all the platforms. |
Ran into this issue myself. Setting it through @refack's original suggestion worked for me. That said, the |
|
nice, it works!! |
For those coming here trying to get C++ 20 working with node addons relying on either Node directly or a derivative (e.g. Electron), don't forget that on Windows you will need to specify |
In my case, the -std:c++17 didn't work with VS 2022 and MS Build. I had to use the CLCompile version mentioned above. I was banging my head up against the wall trying to find out how to override the C++20 that node-gyp was putting into the vcxprj but never could locate the source. This is all because NodeRT uses C++ CX to create the projections, and that is not compatible with C++ 20. "msbuild_settings":{
"ClCompile":{
"LanguageStandard": "stdcpp17",
"AdditionalOptions": "/ZW",
"AdditionalUsingDirectories": [
"%ProgramFiles(x86)%/Microsoft Visual Studio 14.0/VC/lib/store/references",
"%ProgramFiles%/Microsoft Visual Studio 14.0/VC/lib/store/references",
"%ProgramFiles(x86)%/Windows Kits/10/UnionMetadata/10.0.20348.0",
"$(VCToolsInstallDir)/lib/x86/store/references",
"../../",
]
}
} I still have this in the binding.gyp, but it is overridden by the msbuild settings above "msvs_settings": {
"VCCLCompilerTool": {
"AdditionalOptions": ["/ZW", "-std:c++17"],
"DisableSpecificWarnings": [4609],
}
}, |
In my case, node-gyp was adding both that and the |
Verbose output (from npm or node-gyp):
e:\visual studio项目\dsted\source\cpp-addon\svlaunchdll_jswrap.cc(135): error C7525: 内联变量至少需要 "/std:c++17" (编译源文件 ..\cpp-
addon\svlaunchdll_jswrap.cc) [E:\Visual Studio项目\DSTed\Source\build\SVLaunchDLL.vcxproj]
I need C++17, seriously.
cpp-addon.zip
The text was updated successfully, but these errors were encountered: