通过node-gyp将库添加到节点模块

时间:2019-07-11 16:55:57

标签: node.js node-gyp

我正在尝试通过node-gyp构建节点模块。

这是我的binding.gyp文件:

{
  "targets": [
    {
      "target_name": "voxygen",
      "sources": [ "addon/voxygen.cc", "addon/baratinoo.h", "addon/tts.h", "addon/tts.cpp", "addon/baratinooio.h", "addon/baratinooio.cpp" ],
      "conditions": [
        ["OS==\"mac\"", {
          "libraries": [
            "<(module_root_dir)/lib/darwin/libbaratinoo.dylib"
          ]
        }],
        ["OS==\"linux\"", {
          "libraries": [
            "<(module_root_dir)/lib/linx64/libbaratinoo.so"
          ]
        }]
      ]
    }
  ]
}

运行node-gyp configure && node-gyp build时,正确生成了节点模块,但是当我尝试将其加载到节点项目中时,得到:

internal/modules/cjs/loader.js:800
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: dlopen(/xxx/build/Release/voxygen.node, 1): Library not loaded: libbaratinoo.dylib
  Referenced from: /xxx/build/Release/voxygen.node
  Reason: image not found

如何确保节点模块找到其依赖的库?

该库位于:myProject/lib/<darwin|linx64>/libbaratinoo.<dylib|so>

节点模块生成为myProject/build/Release/voxygen.node

0 个答案:

没有答案