【发布时间】:2018-01-03 08:12:21
【问题描述】:
我正在为 Node.js 编写 C++ 插件。尝试使用名为 libSample.so 的示例库,其中声明了函数 printHello:
void printHello() {
std::cout << "Hello World\n";
}
效果很好。(使用node-gyp configure build编译并执行node ./)
当我尝试使用另一个更复杂的库 libCore.so 时。开始执行时产生以下错误。编译配置通过find:
module.js:597
return process.dlopen(module, path._makeLong(filename));
^
Error: libPlayerCore.so: cannot open shared object file: No such file or directory
at Error (native)
at Object.Module._extensions..node (module.js:597:18)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/jasurn/CLionProjects/JsTest/hello.js:2:15)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
libCore.so 的一些用法
//#include <core.h> definition of core library lies in this header
void CreateObject(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Object> obj = Object::New(isolate);
obj->Set(String::NewFromUtf8(isolate, "msg"), args[0]->ToString());
//usage of core library
Core core;
args.GetReturnValue().Set(obj);
}
binding.gyp 文件:路径正确,因为它与另一个库一起使用:)
{
"targets": [
{
"target_name": "addon",
"sources": [ "hello.cc" ],
"libraries": [
"/home/jasurn/CLionProjects/JsTest/libPlayerCore/lib/libCore.so"
]
}
]
}
我将不胜感激您的回答或建议!
【问题讨论】:
-
错误很明显,节点找不到你的插件库。您可以找到有关节点如何对模块进行搜索的相关信息here。
-
@VTT 有趣的是它在同一目录中找到了另一个库。但是当我尝试使用 libCore.so 时。它显示这样的错误。谢谢你的链接!
标签: c++ node.js add-on node.js-addon