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

发布于 2025-01-05 03:36:34 字数 804 浏览 3 评论 0原文

我正在为同事的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弃爱 2025-01-12 03:36:34

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

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

在 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:

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

(On a Mac, that would be DYLD_LIBRARY_PATH.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文