Error: Cannot open shared object file: No such file or directory
Error: Cannot open shared object file: No such file or directory
我正在为 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"
]
}
]
}
如有答复或建议,我将不胜感激!
找到了简单的解决方案,但我可能不适合长期开发。我认为问题出在共享库所需的依赖库上。您可以在终端上通过命令查看需要的库 lld libCore.so
linux-vdso.so.1 => (0x00007ffcae9d6000)
libasound.so.2 => /usr/lib/x86_64-linux-gnu/libasound.so.2 (0x00007fa19dc07000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa19d9e9000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa19d7e5000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa19d45c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa19d153000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa19cf3a000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa19cb73000)
/lib64/ld-linux-x86-64.so.2 (0x00005637d3532000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa19c96b000)
在我的共享库的依赖库列表上方。
解决方案:
您应该将共享库复制到 /usr/lib 位置。这样解决了我的问题。
cp path/where/yourLocated/libCore.so /usr/lib
我正在为 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"
]
}
]
}
如有答复或建议,我将不胜感激!
找到了简单的解决方案,但我可能不适合长期开发。我认为问题出在共享库所需的依赖库上。您可以在终端上通过命令查看需要的库 lld libCore.so
linux-vdso.so.1 => (0x00007ffcae9d6000)
libasound.so.2 => /usr/lib/x86_64-linux-gnu/libasound.so.2 (0x00007fa19dc07000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa19d9e9000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa19d7e5000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa19d45c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa19d153000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa19cf3a000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa19cb73000)
/lib64/ld-linux-x86-64.so.2 (0x00005637d3532000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa19c96b000)
在我的共享库的依赖库列表上方。
解决方案:
您应该将共享库复制到 /usr/lib 位置。这样解决了我的问题。
cp path/where/yourLocated/libCore.so /usr/lib