【发布时间】:2019-07-02 13:00:29
【问题描述】:
我正在尝试使用我同事编写的代码为节点创建自己的 c++ 插件。
它编译为file.node,然后当我尝试在节点中使用它时它崩溃了。
我尝试过预构建库,然后使用 library.dylib 并通过 node-gyp 一起构建它。
这两种方法都会编译并在运行时抛出错误。
我还能做什么?
我正在开发 OSX Mojave。
我已经检查过:
整个错误:
dyld: lazy symbol binding failed: Symbol not found:
__ZN3mds7computeERNSt3__16vectorINS1_IdNS0_9allocatorIdEEEENS2_IS4_EEEE
Referenced from: /.../node_folder/build/release/file.node
Expected in: flat namespace
我的 gyp 文件:
{
"targets": [
{
"target_name": "name",
"sources": ["file.cc"],
"include_dirs": [
"<!(node -e \"require('nan')\")",
"/path/to/cpp/src/"
],
"link_settings": {
"libraries": ["-L/path/to/dylib/directory"]
},
"libraries": ["-L/path/to/dylib/directory"]
}
]
}
我的 package.json
{
...
"dependencies": {
"nan": "^2.12.1",
"node-gyp": "^3.8.0"
},
"scripts": {
"compile": "node-gyp rebuild",
"start": "node index.js"
},
"gypfile": true
}
我的绑定文件:
#include <nan.h>
#include <iostream>
#include <my_header_file.h>
using namespace v8;
NAN_METHOD(compute)
{
if (!info[0]->IsArray())
{
Nan::ThrowTypeError("Argument myst be an array");
return;
}
...
std::vector<std::vector<double>> vector;
... (filling the vector with data)
//static std::vector<std::vector<double>> compute(std::vector<std::vector<double>> & distances_matrix);
mds::compute(vector);
}
NAN_MODULE_INIT(Initialize)
{
NAN_EXPORT(target, compute);
}
NODE_MODULE(addon, Initialize);
【问题讨论】:
-
你能解开:
__ZN3mds7computeERNSt3__16vectorINS1_IdNS0_9allocatorIdEEEENS2_IS4_EEEE好吗?你显然有一个缺失的符号。知道它是什么可能会使修复变得显而易见。 -
@MartinBonner 我已经编辑了 cpp 代码 -> 我已经添加了我认为会抛出它的方法。
-
@MartinBonner 我们怎样才能对符号进行解构?有这样的工具吗?
-
demangler.com@Jonathan