Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot open shared object file: No such file or directory

I was writing C++ Addon for Node.js. Tried to use sample library called libSample.so which has declaration of function printHello:

void printHello() {
    std::cout << "Hello World\n";
}

It worked fine.(Compiled using node-gyp configure build and executed node ./ )

When I tried to use another more complex library called libCore.so. The following error produced when started to execute. Compilation and configure passed 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)

some piece of usage 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);
    }

The binding.gyp file: the path is correct, because it is worked with another library :)

{
  "targets": [
    {
      "target_name": "addon",
      "sources": [ "hello.cc" ],
      "libraries": [
        "/home/jasurn/CLionProjects/JsTest/libPlayerCore/lib/libCore.so"
                ]
    }
  ]
}

I will be appreciated for answers or suggestions!

like image 244
Jasurbek Nabijonov Avatar asked Oct 17 '22 08:10

Jasurbek Nabijonov


1 Answers

Found simple solution, but i maybe not okay for long-development. I think problem was with dependency libraries needed for your shared library. You can see needed libraries by command on terminal 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)

Above the list of dependent libraries for my shared library.

SOLUTION:

You should copy your shared library to /usr/lib location. This way solved my problem.

cp path/where/yourLocated/libCore.so /usr/lib 
like image 88
Jasurbek Nabijonov Avatar answered Oct 30 '22 23:10

Jasurbek Nabijonov