0

I am compiling a Node C++ Add-on using cmake-js. I have dynamic library I am referencing in my C code. I.e.:

*src
 MyAddon.cpp
 *foo
  *include
  *lib
   *linux64
    libfoo.so

That compiles fine. But I get an error when I run

How do I ensure libfoo.so is deployed in a way that it can be linked at runtime?

Adding to files in package.json, doesn't work. Can I set LD_LIBRARY_PATH in package.json?

griffin2000
  • 709
  • 9
  • 26

1 Answers1

1

So worked this out. The trick was to ensure rpath was set correctly (the issue was that rpath is set to an absolute path by default so it would work locally but not when deployed).

You can see this when you run readelf on the .node file:

readelf -d build/Release/addon.node 

Will return something like this. Note the absolute paths

Dynamic section at offset 0x2fd9d30 contains 31 entries:
    .
    .
     0x000000000000000f (RPATH)              Library rpath: [/home/user/foobartest/foo/lib]

The only way to fix this I could find was to do this in the CMake file:

set(  CMAKE_SKIP_RPATH on )
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-rpath,foo/lib")

Then ensure at runtime LD_LIBRARY_PATH was set correctly using by setting env.process.LD_LIBRARY_PATH.

griffin2000
  • 709
  • 9
  • 26