[英]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.