我想在 Visual Studio 2015 中使用包含 C++ 和 C# 代码的 dll 创建本机节点扩展。我无法使其工作如下我自己的指示 https://stackoverflow.com/q/11257690/709537去年的,这是基于最新的node-gyp
.
不使用时/clr
选项,我可以运行如下所示的程序。
console.log("1");
const addon = require('./build/Release/addon');
console.log("2");
启用时/clr
,仅执行对 log 的第一次调用。在调试模式下编译 dll 时,我收到以下消息:
如何修复/调试这个问题?
(我知道有优势,但我正在尝试采用node-gyp方式)
在 VS2015 中尝试所有(?)编译器和链接器选项失败后,我找到了如何设置我的binding.gyp
相反,为了让 .Net 正常工作:
{
"targets": [
{
"target_name": "addon",
"sources": [ "hello.cc" ],
"msbuild_settings": {
"ClCompile": {
"CompileAsManaged": "true",
"ExceptionHandling": "Async",
},
},
}
]
}
我通过成功执行以下托管和非托管代码组合来验证构建:
#include <node.h>
#include <v8.h>
namespace demo {
#pragma managed
void callManaged()
{
System::String^ result = gcnew System::String("hola");
System::Console::WriteLine("It works: " + result);
}
#pragma unmanaged
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
callManaged();
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "woooooorld"));
}
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
NODE_MODULE(addon, init)
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)