Error Compiling C++/CLI Module.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.7k
- Forks
- 1.9k
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 5
Description
Hi. I need to compile a Managed C++ module in a Node.JS application. I read online that I need to enable CLI with the /clr flag, and set the msvs-settings and msbuild_settings attributes, it's still not working for me. I receive this error message:
cl : Command line error D8016: '/clr' and '/EHs' command-line options are incompatible [C:\MyProject\native-modules\encryption-utilities\addon\ build\encrypt.vcxproj]
I've gotten the information from this page: https://github.com/nodejs/node-gyp/issues/568
Here is my binding.gyp below. I've added the three items that are mentioned in this Issue ((1) cflags_cc, (2) msvs_settings, and (3) msbuild_settings), but it's still not working for me.
Thank you.
{
"targets": [
{
"target_name": "encrypt",
'conditions': [
['OS=="mac"', {
"xcode_settings": {
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
"GCC_ENABLE_CPP_RTTI": "YES",
"OTHER_CFLAGS": ["-mmacosx-version-min=10.7", "-std=c++11", "-stdlib=libc++"],
"OTHER_CPLUSPLUSFLAGS": ["-mmacosx-version-min=10.7", "-std=c++11", "-stdlib=libc++"]
},
'defines': [
'LINUX_DEFINE',
'_MAC',
'_ULONGLONG',
],
"cflags": ["-Wall", "-std=c++11", '-fexceptions', '-Wno-writable-strings'],
"cflags!": ['-fno-exceptions', '-Wwritable-strings'],
"cflags_cc!": ['-fno-exceptions', '-Wwritable-strings'],
"cflags_cc": ['-fexceptions', '-Wno-writable-strings'],
"include_dirs": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include"
]
}],
['OS=="win"', {
'defines+': [
'WIN_DEFINE',
'INCLUDE_SIGNATURE_ENCRYPTION',
'WIN64',
'WIN32',
'_WIN32',
"_WIN32_WINNT=0x0601",
"_WINSOCK_DEPRECATED_NO_WARNINGS",
"_HAS_EXCEPTIONS=2",
"_SCL_SECURE_NO_WARNINGS",
"UNICODE",
"_UNICODE",
"_NO_ASYNCRTIMP",
"BOOST_ERROR_CODE_HEADER_ONLY"
],
'msbuild_toolset': 'v141',
{
'cflags_cc': [
'/clr'
],
}],
'msvs_settings': {
'VCCLCompilerTool': {
'RuntimeLibrary':'MultiThreadedDLL'
}
},
'msbuild_settings': {
'ClCompile': {
'CompileAsManaged':'true' # can be safe, pure
}
},
"include_dirs": [
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/shared",
],
# "run_as": {
# "action": ['C:/Program Files/nodejs/node.exe', '$(ProjectDir)/../../out/encrypt.js', ],
# },
"configurations": {
"Debug": {
'defines': [
'DEBUG',
'_DEBUG'
],
'library_dirs': [
],
},
"Release": {
'defines': [
'NDEBUG',
],
'library_dirs': [
],
}
},
"libraries": [
"crypt32.lib",
"winhttp.lib",
"httpapi.lib",
"bcrypt.lib",
"ws2_32.lib",
"iphlpapi.lib"
]
}]
],
"sources": [
"hello.cc",
"aes.cpp",
"base64.cpp",
"crypt.cpp",
"StringUtil.cpp"
],
"cflags": ["-Wall", "-std=c++11"],
"cflags!": ['-fno-exceptions'],
"cflags_cc!": ['-fno-exceptions'],
"include_dirs": [
"<!(node -e \"require('nan')\")",
"addon",
"addon/include",
"../addon/include",
"C:/Projects/C++/vcpkg/installed/x64-windows/include",
"include",
".."
]
},
{
"target_name": "copy_binary",
"type": "none",
"dependencies": ["encrypt"],
'conditions': [
[
'OS=="mac"', {
"copies": [
{
"destination": "<(module_root_dir)/mac/",
"files": ["<(module_root_dir)/build/Release/encrypt.node"]
}
],
}
],
[
'OS=="win"', {
'msbuild_toolset': 'v141',
{
'cflags_cc': [
'/clr'
],
}],
'msvs_settings': {
'VCCLCompilerTool': {
'RuntimeLibrary':'MultiThreadedDLL'
}
},
'msbuild_settings': {
'ClCompile': {
'CompileAsManaged':'true' # can be safe, pure
}
},
"configurations": {
"Debug": {
"copies": [
{
"destination": "<(module_root_dir)/win32/",
"files": ["<(module_root_dir)/build/Debug/encrypt.node", "<(module_root_dir)/build/Debug/encrypt.pdb"]
}
]
},
"Release": {
"copies": [
{
"destination": "<(module_root_dir)/win32/",
"files": ["<(module_root_dir)/build/Release/encrypt.node", "<(module_root_dir)/build/Release/encrypt.pdb"]
}
]
},
}
}
],
]
}
]
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the pasted binding.gyp and the reported D8016 error, then inspect the generated encrypt.vcxproj and node-gyp's Windows build configuration. Reproduce the build with the shown C++/CLI settings and determine which compiler options are being emitted. Done means the addon compiles without the incompatible-option error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, node.js
- Domain
- build-system, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100