[英]dyld: lazy symbol binding failed: Symbol not found. Expected in: flat namespace
I'm trying to create own c++ addon to node from code that was written by my collegue.我正在尝试从我的同事编写的代码创建自己的 C++ 插件到节点。
It compiles to file.node
and then it crashes when I try to use it in node.它编译为
file.node
,然后当我尝试在 node 中使用它时崩溃。
I have tried to prebuild library, then use library.dylib
and also to build it together by node-gyp.我尝试预构建库,然后使用
library.dylib
并通过 node-gyp 将它构建在一起。
Both of these approaches compile and throw an error on runtime.这两种方法都会编译并在运行时抛出错误。
What else can I do?我还可以做些什么?
I'm working on OSX Mojave.我在 OSX Mojave 上工作。
I've checked:我检查过:
How to include c++ libraries so that node-gyp can link?
如何包含 C++ 库以便 node-gyp 可以链接?
Whole error:整个错误:
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
My gyp file:我的 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"]
}
]
}
My package.json我的 package.json
{
...
"dependencies": {
"nan": "^2.12.1",
"node-gyp": "^3.8.0"
},
"scripts": {
"compile": "node-gyp rebuild",
"start": "node index.js"
},
"gypfile": true
}
My binding file:我的绑定文件:
#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);
I see you are importing your header at #include <my_header_file.h>
.我看到您正在
#include <my_header_file.h>
导入您的标题。 If you are calling a method from your custom class for your NAN_METHOD you need to call it inline or else the compiler will not know where to look.如果您正在为您的 NAN_METHOD 从您的自定义类调用一个方法,您需要内联调用它,否则编译器将不知道在哪里查找。
Run "c++filt (missing symbol)" to demangle and see where you need to call it运行“c++filt (missing symbol)”来解压,看看你需要在哪里调用它
Example Instead of method()
Use Class::method()
示例而不是
method()
使用Class::method()
Your missing symbol demangled is mds::compute(std::__1::vector<std::__1::vector<double, std::__1::allocator<double> >, std::__1::allocator<std::__1::vector<double, std::__1::allocator<double> > > >&)
你丢失的符号是
mds::compute(std::__1::vector<std::__1::vector<double, std::__1::allocator<double> >, std::__1::allocator<std::__1::vector<double, std::__1::allocator<double> > > >&)
I have solved from https://github.com/nodejs/node-gyp/issues/1380 ,我已经从https://github.com/nodejs/node-gyp/issues/1380解决了,
The missing symbol's name indicates it's not using C linkage.
缺少符号的名称表明它没有使用 C 链接。
I just add extern "C" in the header file我只是在头文件中添加了extern "C"
extern "C" double add(double a ,double b);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.