dyld:惰性符号绑定失败:找不到符号。预期在:平面命名空间
dyld: lazy symbol binding failed: Symbol not found. Expected in: flat namespace
我正在尝试根据我同事编写的代码创建自己的节点 C++ 插件。
它编译为 file.node
,然后当我尝试在节点中使用它时它崩溃了。
我尝试过预构建库,然后使用 library.dylib
并通过 node-gyp 一起构建它。
这两种方法都会编译并在运行时抛出错误。
我还能做什么?
我正在研究 OSX Mojave。
我检查过:
How to include c++ libraries so that node-gyp can link?
dyld: lazy symbol binding failed
整个错误:
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>
导入 header。
如果您从自定义 class 中为您的 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,
解决了
The missing symbol's name indicates it's not using C linkage.
我只是在头文件中添加extern "C"
extern "C" double add(double a ,double b);
我正在尝试根据我同事编写的代码创建自己的节点 C++ 插件。
它编译为 file.node
,然后当我尝试在节点中使用它时它崩溃了。
我尝试过预构建库,然后使用 library.dylib
并通过 node-gyp 一起构建它。
这两种方法都会编译并在运行时抛出错误。
我还能做什么?
我正在研究 OSX Mojave。
我检查过:
How to include c++ libraries so that node-gyp can link?
dyld: lazy symbol binding failed
整个错误:
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>
导入 header。
如果您从自定义 class 中为您的 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,
解决了The missing symbol's name indicates it's not using C linkage.
我只是在头文件中添加extern "C"
extern "C" double add(double a ,double b);