[英]dyld: lazy symbol binding failed: Symbol not found. Expected in: flat namespace
我正在尝试从我的同事编写的代码创建自己的 C++ 插件到节点。
它编译为file.node
,然后当我尝试在 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);
我看到您正在#include <my_header_file.h>
导入您的标题。 如果您正在为您的 NAN_METHOD 从您的自定义类调用一个方法,您需要内联调用它,否则编译器将不知道在哪里查找。
运行“c++filt (missing symbol)”来解压,看看你需要在哪里调用它
示例而不是method()
使用Class::method()
你丢失的符号是mds::compute(std::__1::vector<std::__1::vector<double, std::__1::allocator<double> >, std::__1::allocator<std::__1::vector<double, std::__1::allocator<double> > > >&)
我已经从https://github.com/nodejs/node-gyp/issues/1380解决了,
缺少符号的名称表明它没有使用 C 链接。
我只是在头文件中添加了extern "C"
extern "C" double add(double a ,double b);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.