Node.js 模块 - 添加链接依赖
我正在为同事的 C 库开发 Node.js 包装器模块。该库以共享对象 (.so) 形式创建,用于动态链接。
我的 CPP 模块文件以
#include "path/to/lib/source/lib.h"
以下 wscript 开头并使用以下 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 文件。
非常感谢任何帮助!
I'm working on a Node.js wrapper module for a colleagues C library. The library is created in Shared Object (.so) form for dynamic linking.
My CPP module file begins with
#include "path/to/lib/source/lib.h"
and is built with the following 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'
When I then proceed to call into my module, which in turns call the library, i get the following error:
node: symbol lookup error: <path/to/module.node>:
undefined symbol: <name of library call>
I tried dumping the dependencies of the module with 'ldd module.node' and I got a little suspicious as it doesn't mention my .so file.
Any help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您知道动态链接器是否可以找到您的库吗?尝试将库路径添加到 LD_LIBRARY_PATH。您可以在使用测试脚本调用 Node 之前在 shell 中运行此命令:(
在 Mac 上,该路径为 DYLD_LIBRARY_PATH。)
Do you know if the dynamic linker can find your library? Try adding the library path to your LD_LIBRARY_PATH. You can run this in the shell before you invoke Node with your test script:
(On a Mac, that would be
DYLD_LIBRARY_PATH
.)