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

假如想象 提交于 2020-01-01 18:17:48

问题


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?


回答1:


Looks like I have to escape it like this:

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

Now it works like expected.



来源:https://stackoverflow.com/questions/42512623/how-to-build-nodejs-c-addon-depending-on-a-shared-library-with-relative-locati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!