Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build nodejs C++ addon depending on a shared library with relative location

I'm trying to build a node.js C++ using node-gyp but can't figure out how to specify the -Wl,-rpath,$ORIGIN so that when loaded from node it could find shared object library that is in the same directory as addon.node.

I have tried setting my binding.gyp like this:

"libraries": [
          "-L../../install_release_x64/",
          "-llibppp"
        ],
        "ldflags": [
          "-Wl,-rpath,'$ORIGIN'"
        ],
        "cflags_cc": [
          "-fexceptions",
          "-fPIC",
          "-Wno-unknown-pragmas"
        ]

but when I run $ readelf -d addon.node the result is like this:

 Dynamic section at offset 0x7d10 contains 29 entries:
Tag        Type                         Name/Value
0x0000000000000001 (NEEDED)             Shared library: [liblibppp.so]
0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
0x000000000000000e (SONAME)             Library soname: [addon.node]
0x000000000000000f (RPATH)              Library rpath: [RIGIN]
0x000000000000000c (INIT)               0x37a0

The expected result is Library rpath: [$ORIGIN]

Any ideas what's node-gyp doing to my $ORIGIN special keyword?

like image 861
Darien Pardinas Avatar asked Feb 28 '17 15:02

Darien Pardinas


1 Answers

Looks like I have to escape it like this:

"ldflags": [
    "-Wl,-rpath,'$$ORIGIN'"
],

Now it works like expected.

like image 95
Darien Pardinas Avatar answered Sep 20 '22 11:09

Darien Pardinas