node.js - 如何在 binding.gyp node-gyp 中为 node.js 扩展添加对静态库的依赖

标签 node.js node-gyp

我有一个简单的 binding.gyp 文件来构建我的 node.js 扩展。我想改变库“mylib”的链接方法,静态链接而不是使用共享库。

{
  "targets": [
    {
      "target_name": "myext",
      "sources": [
        "code/main.cpp",
        "code/load.cpp",
        "include/load.h"
      ],
      "include_dirs": [
        "include", "../Library/include"
      ],
      "libraries": [
        "-lmylib", "-L/home/admin/MyLib/Library/binaries/linux/Release"
      ],
      "cflags!": [ "-fno-exceptions" ],
      "cflags": [ "-std=c++11" ],
      "cflags_cc!": [ "-fno-exceptions" ]
    }
  ]
}

mylib 的静态和共享版本在同一目录下:

# ls /home/admin/MyLib/Library/binaries/linux/Release
libmylib.a libmylib.so

我想静态链接以避免库安装/加载问题。

最佳答案

您可以让 node-gyp 使用内置变量 module_root_dir 为您插入路径 如果我正确解释您的代码,请将您的 libraries 更改为例如:

"libraries": [
    "-lmylib",
    "-L<(module_root_dir)/../Library/binaries/linux/Release"
],

可能会成功。虽然我不确定它是否会与 .a.so 版本链接,但指定您可以尝试:

"libraries": [
    "<(module_root_dir)/../Library/binaries/linux/Release/libmylib.a"
],

带有out -L 前缀和-lmylib。此外,我有点不确定是否允许您遍历根目录。我之前没有使用模块根目录上方的任何东西进行测试。除此之外,您应该一切顺利。

关于node.js - 如何在 binding.gyp node-gyp 中为 node.js 扩展添加对静态库的依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18748224/

相关文章:

node.js - 安装 Node 模块时 node-gyp 重建错误

node.js - 运行 npm install : . node-gyp/6.14.4/include/node/v8.h:21:10 时出错: fatal error : 'utility' 文件未找到

node.js - 我可以在 OpenVZ 上运行 8 的 Debian 上运行 NPM/NodeJS 应用程序吗?

javascript - 使用cheerio获取所有包含的js

node.js - 使用 NodeJS 将附件添加到 couch db 中的文档

node.js - node-expat@2.3.17 安装脚本失败 - 任何 NPM 安装都会发生

javascript - 如何使用 npm Passport 在 OAuth2 url 中订购请求参数

javascript - MongoDB, Node : Query ISODate fields with a query not build directly in find operation

node.js - 如何告诉 node-gyp/node-sass 我已经有了我的 Node header ?

node.js - 安装 npm 包时出现“node-gyp”错误