简体   繁体   English

OSX 10.7.5上的node-gyp - dyld:惰性符号绑定失败:找不到符号

[英]node-gyp on OSX 10.7.5 — dyld: lazy symbol binding failed: Symbol not found

I've searched quite a bit, and the closest thing I found to this same question was this (also unanswered) question: 我搜索了很多,而我在同一个问题上找到的最接近的是这个(也是没有答案的)问题:

Symbol not found: _libintl_gettext 找不到符号:_libintl_gettext

I'm attempting to make a thin c++ wrapper for libpuzzle. 我正在尝试为libpuzzle创建一个瘦c ++包装器。

$ node --version
v0.8.18
$ npm --version
1.2.4
$ node-gyp --version
v0.8.3

Source code on github github上的源代码

Trying to build (I've hand shorted the paths with ...) 试图建立(我用......做短路径)

$ node-gyp clean configure build && node test.js 
gyp info it worked if it ends with ok
gyp info using node-gyp@0.8.3
gyp info using node@0.8.18 | darwin | x64
gyp info spawn python
gyp info spawn args [ '/opt/local/lib/node_modules/node-gyp/gyp/gyp',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/.../node-puzzle/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/opt/local/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/.../.node-gyp/0.8.18/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/.../.node-gyp/0.8.18',
gyp info spawn args   '-Dmodule_root_dir=/.../node-puzzle',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
  CXX(target) Release/obj.target/puzzle/puzzle.o
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  SOLINK_MODULE(target) Release/puzzle.node
  SOLINK_MODULE(target) Release/puzzle.node: Finished
gyp info ok 
dyld: lazy symbol binding failed: Symbol not found: __Z19puzzle_init_contextP14PuzzleContext_
  Referenced from: /.../node-puzzle/build/Release/puzzle.node
  Expected in: dynamic lookup

dyld: Symbol not found: __Z19puzzle_init_contextP14PuzzleContext_
  Referenced from: /.../node-puzzle/build/Release/puzzle.node
  Expected in: dynamic lookup

Ok, so this error makes sense to me, clearly it can't load a dynamic library. 好吧,所以这个错误对我来说很有意义,显然它无法加载动态库。

At first I thought I had to adjust my binding.gyp to include the linker settings, so I tried several different configurations. 起初我以为我必须调整我的binding.gyp以包含链接器设置,所以我尝试了几种不同的配置。 At the moment this is what it looks like: 目前这就是它的样子:

{
    "targets": [
        {
            "target_name": "puzzle",
            "sources": [ "puzzle.cc" ],
            "link_settings": {
                "libraries": [
                    "/opt/local/lib/libgd.dylib",
                    "/opt/local/lib/libpuzzle.dylib"
                ],
            }
        }
    ]
}

I have the libs here: 我有libs:

$ ll /opt/local/lib/libpuzzle.*
-rwxr-xr-x  1 root  admin    19K Jan 30 21:24 /opt/local/lib/libpuzzle.1.dylib
-rw-r--r--  1 root  admin    20K Jan 30 21:24 /opt/local/lib/libpuzzle.a
lrwxr-xr-x  1 root  admin    17B Jan 30 21:24 /opt/local/lib/libpuzzle.dylib -> libpuzzle.1.dylib
-rwxr-xr-x  1 root  admin   1.3K Jan 30 21:24 /opt/local/lib/libpuzzle.la

$ ll /opt/local/lib/libgd.*
-rwxr-xr-x  1 root  admin   252K Sep  2 23:59 /opt/local/lib/libgd.2.dylib
-rw-r--r--  1 root  admin   289K Sep  2 23:59 /opt/local/lib/libgd.a
lrwxr-xr-x  1 root  admin    13B Sep  2 23:59 /opt/local/lib/libgd.dylib -> libgd.2.dylib
-rwxr-xr-x  1 root  admin   1.2K Sep  2 23:59 /opt/local/lib/libgd.la

I just can't figure out how to get dyld to see them. 我只是无法弄清楚如何让dyld看到它们。 I have tried adjusting DYLD_FRAMEWORK_PATH and DYLD_FALLBACK_LIBRARY_PATH to no avail. 我试过调整DYLD_FRAMEWORK_PATH和DYLD_FALLBACK_LIBRARY_PATH无济于事。

update: output from otool 更新:来自otool的输出

otool -l build/Release/puzzle.node

build/Release/puzzle.node:
Load command 0
      cmd LC_SEGMENT_64
  cmdsize 552
  segname __TEXT
   vmaddr 0x0000000000000000
   vmsize 0x0000000000002000
  fileoff 0
 filesize 8192
  maxprot 0x00000007
 initprot 0x00000005
   nsects 6
    flags 0x0
Section
  sectname __text
   segname __TEXT
      addr 0x0000000000000edc
      size 0x00000000000008d8
    offset 3804
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0
Section
  sectname __stubs
   segname __TEXT
      addr 0x00000000000017b4
      size 0x000000000000010e
    offset 6068
     align 2^1 (2)
    reloff 0
    nreloc 0
     flags 0x80000408
 reserved1 0 (index into indirect symbol table)
 reserved2 6 (size of stubs)
Section
  sectname __stub_helper
   segname __TEXT
      addr 0x00000000000018c4
      size 0x000000000000021c
    offset 6340
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0
Section
  sectname __cstring
   segname __TEXT
      addr 0x0000000000001ae0
      size 0x00000000000001ea
    offset 6880
     align 2^0 (1)
    reloff 0
    nreloc 0
     flags 0x00000002
 reserved1 0
 reserved2 0
Section
  sectname __unwind_info
   segname __TEXT
      addr 0x0000000000001cca
      size 0x000000000000008c
    offset 7370
     align 2^0 (1)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __eh_frame
   segname __TEXT
      addr 0x0000000000001d58
      size 0x00000000000002a8
    offset 7512
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Load command 1
      cmd LC_SEGMENT_64
  cmdsize 472
  segname __DATA
   vmaddr 0x0000000000002000
   vmsize 0x0000000000001000
  fileoff 8192
 filesize 4096
  maxprot 0x00000007
 initprot 0x00000003
   nsects 5
    flags 0x0
Section
  sectname __dyld
   segname __DATA
      addr 0x0000000000002000
      size 0x0000000000000010
    offset 8192
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __got
   segname __DATA
      addr 0x0000000000002010
      size 0x0000000000000010
    offset 8208
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000006
 reserved1 45 (index into indirect symbol table)
 reserved2 0
Section
  sectname __la_symbol_ptr
   segname __DATA
      addr 0x0000000000002020
      size 0x0000000000000168
    offset 8224
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000007
 reserved1 47 (index into indirect symbol table)
 reserved2 0
Section
  sectname __data
   segname __DATA
      addr 0x0000000000002190
      size 0x0000000000000060
    offset 8592
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __const
   segname __DATA
      addr 0x00000000000021f0
      size 0x0000000000000030
    offset 8688
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Load command 2
      cmd LC_SEGMENT_64
  cmdsize 72
  segname __LINKEDIT
   vmaddr 0x0000000000003000
   vmsize 0x0000000000002000
  fileoff 12288
 filesize 6648
  maxprot 0x00000007
 initprot 0x00000001
   nsects 0
    flags 0x0
Load command 3
          cmd LC_ID_DYLIB
      cmdsize 48
         name @rpath/puzzle.node (offset 24)
   time stamp 1 Wed Dec 31 19:00:01 1969
      current version 0.0.0
compatibility version 0.0.0
Load command 4
     cmd LC_SYMTAB
 cmdsize 24
  symoff 12720
   nsyms 138
  stroff 15344
 strsize 3592
Load command 5
            cmd LC_DYSYMTAB
        cmdsize 80
      ilocalsym 0
      nlocalsym 76
     iextdefsym 76
     nextdefsym 19
      iundefsym 95
      nundefsym 43
         tocoff 0
           ntoc 0
      modtaboff 0
        nmodtab 0
   extrefsymoff 0
    nextrefsyms 0
 indirectsymoff 14976
  nindirectsyms 92
      extreloff 14928
        nextrel 6
      locreloff 12288
        nlocrel 50
Load command 6
     cmd LC_UUID
 cmdsize 24
    uuid 9A75E329-2D02-3AC8-A249-A741702EB141
Load command 7
      cmd LC_VERSION_MIN_MACOSX
  cmdsize 16
  version 10.5
      sdk 10.7
Load command 8
          cmd LC_LOAD_DYLIB
      cmdsize 64
         name /opt/local/lib/libssl.1.0.0.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 1.0.0
compatibility version 1.0.0
Load command 9
          cmd LC_LOAD_DYLIB
      cmdsize 64
         name /opt/local/lib/libcrypto.1.0.0.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 1.0.0
compatibility version 1.0.0
Load command 10
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /opt/local/lib/libgd.2.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 3.0.0
compatibility version 3.0.0
Load command 11
          cmd LC_LOAD_DYLIB
      cmdsize 64
         name /opt/local/lib/libpuzzle.1.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 2.0.0
compatibility version 2.0.0
Load command 12
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libstdc++.6.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 52.0.0
compatibility version 7.0.0
Load command 13
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libSystem.B.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 159.1.0
compatibility version 1.0.0
Load command 14
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libgcc_s.1.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 1094.0.0
compatibility version 1.0.0
Load command 15
      cmd LC_FUNCTION_STARTS
  cmdsize 16
  dataoff 12688
 datasize 32
Load command 16
      cmd LC_DATA_IN_CODE
  cmdsize 16
  dataoff 12720
 datasize 0

otool -L build/Release/puzzle.node

build/Release/puzzle.node:
    @rpath/puzzle.node (compatibility version 0.0.0, current version 0.0.0)
    /opt/local/lib/libssl.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /opt/local/lib/libcrypto.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /opt/local/lib/libgd.2.dylib (compatibility version 3.0.0, current version 3.0.0)
    /opt/local/lib/libpuzzle.1.dylib (compatibility version 2.0.0, current version 2.0.0)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1094.0.0)

The symbol that dyld is complaining about is __Z19puzzle_init_contextP14PuzzleContext_ . dyld抱怨的符号是__Z19puzzle_init_contextP14PuzzleContext_ In its unmangled form, it is puzzle_init_context(PuzzleContext_*) . 在其未puzzle_init_context(PuzzleContext_*)形式中,它是puzzle_init_context(PuzzleContext_*) The mangling indicates that it was considered by the compiler to be a C++ symbol. 修改表明编译器认为它是C ++符号。 However, libpuzzle appears to export a pure C interface. 但是,libpuzzle似乎导出了纯C接口。 This means that the symbol it should be looking for is _puzzle_init_context . 这意味着它应该寻找的符号是_puzzle_init_context You can fix this by wrapping the #include <puzzle.h> in an extern "C" { … } block to inform the compiler that the contents of the header should be treated as C code, so it will handle the symbol names by the appropriate rules. 您可以通过将#include <puzzle.h>包装在extern "C" { … }块中来解决此问题,以通知编译器标头的内容应被视为C代码,因此它将处理符号名称适当的规则。

This sort of error is typically detected by the static linker rather than at runtime by the dynamic linker. 这种错误通常由静态链接器检测,而不是在动态链接器的运行时检测到。 The Expected in: dynamic lookup portion of your error message indicates that puzzle.node was linked with -undefined dynamic_lookup . Expected in: dynamic lookup错误消息的Expected in: dynamic lookup部分表示puzzle.node-undefined dynamic_lookup链接。 This tells the static linker not to emit any errors for undefined symbols, but instead to have the dynamic linker attempt to resolve the symbols at runtime. 这告诉静态链接器不要为未定义的符号发出任何错误,而是让动态链接器尝试在运行时解析符号。 This is rarely the behavior you want. 这很少是您想要的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 dyld:惰性符号绑定失败:找不到符号:_yylex - dyld: lazy symbol binding failed: Symbol not found: _yylex 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 dyld:懒惰的符号绑定失败:找不到符号。 预期在:平面命名空间 - dyld: lazy symbol binding failed: Symbol not found. Expected in: flat namespace 惰性符号绑定失败:找不到符号 - Lazy symbol binding failed: symbol not found dyld:懒惰的符号绑定失败:找不到符号:__ZN5boost11this_thread5hiden11sleep_untilERK8timespec(具有…6hidden11sleep_untilERK8timespec) - dyld: lazy symbol binding failed: Symbol not found: __ZN5boost11this_thread5hiden11sleep_untilERK8timespec (have …6hidden11sleep_untilERK8timespec) node-gyp构建提供了未解决的外部符号错误 - node-gyp build gives unresolved external symbol error 找不到Dyld符号错误 - Dyld Symbol not Found Error 使用 node-gyp 异常:LNK2001 未解析的外部符号 - use node-gyp exception : LNK2001 unresolved external symbol 错误 LNK2001:使用 Node-Gyp 的 C++ 中的外部符号无法解析 - error LNK2001: unresolved external symbol in C++ with Node-Gyp
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM