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

标签 node.js gcc node-modules node-gyp compiler-flags

我正在尝试使用 node-gyp 构建一个 node.js C++,但不知道如何指定 -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"
        ]

但是当我运行 $ 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

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

知道 node-gyp 对我的 $ORIGIN 特殊关键字做了什么吗?

最佳答案

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

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

现在它按预期工作。

关于node.js - 如何根据具有相对位置的共享库构建 nodejs C++ 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42512623/

相关文章:

javascript - 使用同构网络应用程序的目的是什么?

c++ - 强制转换尾随返回类型会导致 SFINAE 失败

c - 如何防止 gcc 预处理器删除行继续符?

python - 使用 python 的 subprocess.Popen 将字符串传递给 gcc

node.js - 从 Node 模块获取类似 sytax 的 jquery

node.js - 在项目文件中进行多次更改后,nodemon 崩溃了?

angularjs - Node jS API 和 Angular jS 应该在同一个项目中吗?

javascript - 通过 JavaScript 对象数组中的变量访问字段

node.js - 无效的 ELF header - Argon2 包

node.js - 适用于 Windows 和 Ubuntu 的 NodeJS exec() 命令