我正在为Node.js编写C++插件。尝试使用名为libSample.so的示例库,该库具有函数printHello的声明:
绑定文件.gyp:路径正确,因为它已经与另一个库配合使用 :)
void printHello() {
std::cout << "Hello World\n";
}
它运行得很好。(使用node-gyp configure build
编译并执行node ./
)
当我尝试使用另一个更复杂的库libCore.so时,开始执行时出现以下错误。编译和配置都通过了:
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);
}
绑定文件.gyp:路径正确,因为它已经与另一个库配合使用 :)
{
"targets": [
{
"target_name": "addon",
"sources": [ "hello.cc" ],
"libraries": [
"/home/jasurn/CLionProjects/JsTest/libPlayerCore/lib/libCore.so"
]
}
]
}
我将感激您的回答或建议!