Node.js 模块 - 添加链接依赖

标签 node.js ld waf

我正在为同事的 C 库开发 Node.js 包装器模块。该库以共享对象 (.so) 形式创建,用于动态链接。

我的 CPP 模块文件开始于

#include "path/to/lib/source/lib.h"

并使用以下 wscript 构建

def set_options(ctx):
    ctx.tool_options('compiler_cxx')

def configure(ctx):
    ctx.check_tool('compiler_cxx')
    ctx.check_tool('node_addon')
    ctx.env.append_value('LINKFLAGS', ['-l:lib.so', '-L/path/to/lib.so/'])

def build(ctx):
    t = ctx.new_task_gen('cxx', 'shlib', 'node_addon')
    t.source = ['module.cpp']
    t.target = 'module'

然后,当我继续调用我的模块(该模块又调用库)时,出现以下错误:

node: symbol lookup error: <path/to/module.node>:
undefined symbol: <name of library call>

我尝试使用“ldd module.node”转储模块的依赖项,但我有点怀疑,因为它没有提到我的 .so 文件。

非常感谢任何帮助!

最佳答案

您知道动态链接器是否可以找到您的库吗?尝试将库路径添加到您的 LD_LIBRARY_PATH。在使用测试脚本调用 Node 之前,您可以在 shell 中运行它:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/lib.so/
node test-script.js

(在 Mac 上,这将是 DYLD_LIBRARY_PATH。)

关于Node.js 模块 - 添加链接依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9240550/

相关文章:

node.js - NPM - 错误 : Cannot find module '../'

c - `.eh_frame' 和 collect2.exe : error: ld returned 1 exit status when compiling with MinGW 中的错误重定位地址

macos - 在OSX上使用Waf编译OpenGL/SDL应用程序时,如何抑制 '-arch'和 'x86_64'标志?

python - waf多步构建-目标路径

c++ - 黄金链接器 : specify alignment of sections

eclipse - 将外部构建工具集成到 Eclipse 中的最佳方法是什么?

javascript - Mongoose 对象 :javascript map function not working on adding new keys

node.js - Node 套接字在 Twitter 流 filter.json 上挂起

javascript - Node.JS onoff 未正确拾取 GPIO

c - 将部分拆分为多个内存区域