简体   繁体   English

dyld:懒惰的符号绑定失败:找不到符号。 预期在:平面命名空间

[英]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 可以链接?

dyld: lazy symbol binding failed dyld:懒惰的符号绑定失败

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.

相关问题 dyld:惰性符号绑定失败,opencv - dyld: lazy symbol binding failed, opencv 在Mac上编译C ++代码时处理“ dyld:惰性符号绑定失败:找不到符号”错误 - Handling “dyld: lazy symbol binding failed: Symbol not found” error when compiling C++ code on Mac OSX 10.7.5上的node-gyp - dyld:惰性符号绑定失败:找不到符号 - node-gyp on OSX 10.7.5 — dyld: lazy symbol binding failed: Symbol not found 惰性符号绑定失败:找不到符号 - Lazy symbol binding failed: symbol not found 在平面名称空间中找不到预期的ImportError dlopen()符号 - Importerror dlopen () symbol not found expected in flat namespace 符号未找到,预期在Flat Namespace ObjC ++中 - Symbol Not Found, expected in Flat Namespace ObjC++ SWIG for C ++,未找到符号:预期用于:平面名称空间 - SWIG for C++, Symbol not found: Expected in: flat namespace “符号未找到/预期位于:平面名称空间”实际上是什么意思? - What does "Symbol not found / Expected in: flat namespace" actually mean? dyld:懒惰的符号绑定失败:找不到符号:__ZN5boost11this_thread5hiden11sleep_untilERK8timespec(具有…6hidden11sleep_untilERK8timespec) - dyld: lazy symbol binding failed: Symbol not found: __ZN5boost11this_thread5hiden11sleep_untilERK8timespec (have …6hidden11sleep_untilERK8timespec) 找不到Dyld符号错误 - Dyld Symbol not Found Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM