5

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!

iehrlich
  • 3,572
  • 4
  • 34
  • 43
Jasurbek Nabijonov
  • 1,607
  • 3
  • 24
  • 37
  • 2
    Error is pretty clear, node can not find your addon library. You can find relevant information on how node performs search on modules [here](https://nodejs.org/api/modules.html). – user7860670 Jul 27 '17 at 14:26
  • @VTT The interesting thing is it finds another library in same directory. But when I try to use libCore.so. It displays such error. Thank you for link! – Jasurbek Nabijonov Jul 28 '17 at 05:50

1 Answers1

4

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 
Jasurbek Nabijonov
  • 1,607
  • 3
  • 24
  • 37
  • 1
    Can you explain why it is not an option to add these .so (shared object files) to the /opt/ directory on a linux system? I understand that this question is more about the linux filesystem hierarchy. – Erich Meissner Sep 15 '20 at 19:40
  • 1
    Yeah, I think you can place it there, but then you should link it in the project configuration. I may be wrong because haven't done c++ and node js for a while. Maybe there are new options in 2020. Anyway good luck. – Jasurbek Nabijonov Sep 16 '20 at 21:27