如何根据具有相对位置的共享库构建 nodejs C++ 插件

Dar*_*nas 5 gcc compiler-flags node.js node-gyp node-modules

我正在尝试构建一个 node.js C++ 使用,node-gyp但无法弄清楚如何指定,-Wl,-rpath,$ORIGIN以便从 node 加载时它可以找到与addon.node.

我试过这样设置我的binding.gyp

"libraries": [
          "-L../../install_release_x64/",
          "-llibppp"
        ],
        "ldflags": [
          "-Wl,-rpath,'$ORIGIN'"
        ],
        "cflags_cc": [
          "-fexceptions",
          "-fPIC",
          "-Wno-unknown-pragmas"
        ]
Run Code Online (Sandbox Code Playgroud)

但是当我运行时$ readelf -d addon.node,结果是这样的:

 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
Run Code Online (Sandbox Code Playgroud)

预期的结果是 Library rpath: [$ORIGIN]

任何想法 node-gyp 对我的$ORIGIN特殊关键字做了什么?

Dar*_*nas 5

看起来我必须像这样逃避它:

"ldflags": [
    "-Wl,-rpath,'$$ORIGIN'"
],
Run Code Online (Sandbox Code Playgroud)

现在它按预期工作。