错误:无法打开共享对象文件:没有此类文件或目录

时间:2017-07-27 14:17:52

标签: c++ node.js add-on node.js-addon

我正在为Node.js编写C ++ Addon。试图使用名为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"
                ]
    }
  ]
}

我将非常感谢您的答案或建议!

1 个答案:

答案 0 :(得分:1)

找到了简单的解决方案,但我可能不适合长期开发。我认为问题在于共享库所需的依赖库。您可以在终端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)

在我的共享库的依赖库列表上方。

<强> SOLUTION:

您应该将共享库复制到/ usr / lib位置。这种方式解决了我的问题。

cp path/where/yourLocated/libCore.so /usr/lib