应用程序中编译C ++ / CLI时出错"/>
在Node.JS应用程序中编译C ++ / CLI时出错
我需要在Node.JS应用程序中编译托管C ++模块。我在网上阅读了我需要使用/ clr标志启用CLI的信息,并设置了msvs-settings和msbuild_settings属性,但它仍然对我不起作用。我收到此错误消息:
cl:命令行错误D8016:'/ clr'和'/ EHs'命令行选项不兼容[C:\ MyProject \ native-modules \ encryption-utilities \ addon \build \ encrypt.vcxproj]
我已经从此页面获取信息:
这是我的binding.gyp。
谢谢。
{
"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",
"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"]
}
]
},
}
}
],
]
}
]
}
回答如下:我对node.js或.gyp文件了解不多,但我确实知道您遇到的错误。 D8016表示“ / clr表示/ EHa,并且不能使用/ clr指定任何其他/ EH编译器选项”。当您导入旧项目文件或将/clr
添加到现有项目时,可能会出现此问题。
解决它的官方方法是在Visual Studio中打开有问题的.vcxproj
项目文件,导航到项目属性/配置属性/ C / C ++ /代码生成,然后从中更改启用C ++异常] “ 是具有外部C函数(/ EHs)”到“ 是具有SEH异常(/ EHa)”。]
要在VS之外执行此操作,请在任何文本(或xml)编辑器中打开.vcxproj
文件,然后删除以下行:
<ExceptionHandling>SyncCThrow</ExceptionHandling>
或替换为:
<ExceptionHandling>Async</ExceptionHandling>
更多推荐
在Node.JS应用程序中编译C ++ / CLI时出错
发布评论