Ars*_*sha 5 c++ node.js node-gyp
我试图制作一个节点本机插件并且node-gyp configure build工作正常,当我需要在 javascript 文件中测试插件并使用它正常运行node main它然后给出错误时Error: Module did not self register, code: ERR_DLOPEN_FAILED,这里是我到目前为止的代码:
绑定.gyp
{
"targets": [
{
"target_name": "hello",
"source": ["hello.cc"]
}
]
}
Run Code Online (Sandbox Code Playgroud)
你好.cc
#include <node/node.h>
#include <node/v8.h>
using namespace v8;
void Method(const FunctionCallbackInfo<Value>&args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world").ToLocalChecked());
}
void Initialize(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize);
Run Code Online (Sandbox Code Playgroud)
main.js
const hello = require("./build/Release/hello");
console.log(hello.hello())
Run Code Online (Sandbox Code Playgroud)
我该如何修复这个错误?谢谢。
| 归档时间: |
|
| 查看次数: |
11438 次 |
| 最近记录: |