由rpath设置的dylib未在OS X中加载

时间:2016-06-02 01:58:39

标签: macos package-managers dyld

我正在创建一个包管理器,并希望通过在编译时设置rpath选项来确保包使用正确的依赖库。但它在OS X(10.11)中让我感到惊讶,这就是问题所在:

$ otool -L /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951 
/opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951:
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /opt/starman/software/isl/0.17.1/104994def2b7fb2dae7950b42205eb718a46ee0c/lib/libisl.15.dylib (compatibility version 18.0.0, current version 18.1.0)
    /opt/starman/software/mpc/1.0.3/6058925218009b8ab17e07333dc54de334134f6e/lib/libmpc.3.dylib (compatibility version 4.0.0, current version 4.0.0)
    /opt/starman/software/mpfr/3.1.4/f142dfcda3b56650a8c9cfe2fdd09ffdf7283a00/lib/libmpfr.4.dylib (compatibility version 6.0.0, current version 6.4.0)
    /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib (compatibility version 14.0.0, current version 14.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

请参阅gmp版本14.0.0

$ /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951 
dyld: Library not loaded: /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib
  Referenced from: /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
  Reason: Incompatible library version: f951 requires version 14.0.0 or later, but libgmp.10.dylib provides version 13.0.0
Trace/BPT trap: 5

它说正确路径中的gmp未加载,因为其版本为13.0.0,但它是14.0.0!我知道我在另一个路径中安装了旧版本gmp,所以在我从DYLD_LIBRARY_PATH删除其lib路径后,问题就消失了,但不应该rpath解决这个问题?

为什么dyld打印gmp的正确路径,但实际上使用了错误的旧路径? OS X中有什么技巧吗?谢谢你的帮助!

编辑1 /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib的版本被检查为

$ otool -l /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib
...
      cmdsize 120
         name /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib (offset 24)
   time stamp 1 Thu Jan  1 08:00:01 1970
      current version 14.0.0
compatibility version 14.0.0
...

年龄较大的gmp

$ otool -l /opt/software/gmp/6.0.0a/0/lib/libgmp.10.dylib
...
         name @rpath/lib/libgmp.dylib (offset 24)
   time stamp 1 Thu Jan  1 08:00:01 1970
      current version 13.0.0
compatibility version 13.0.0
...

EIDT 2

根据0xced,我运行调试加载过程为(完整输出为here ):

$ export DYLD_PRINT_LIBRARIES="1"
$ /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
dyld: loaded: /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
dyld: loaded: /usr/lib/libiconv.2.dylib
dyld: loaded: /opt/starman/software/isl/0.17.1/104994def2b7fb2dae7950b42205eb718a46ee0c/lib/libisl.15.dylib
dyld: loaded: /opt/software/packman.active/lib/libmpc.3.dylib
dyld: loaded: /opt/software/packman.active/lib/libmpfr.4.dylib
dyld: loaded: /opt/software/packman.active/lib/libgmp.10.dylib
dyld: unloaded: /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
dyld: unloaded: /opt/starman/software/isl/0.17.1/104994def2b7fb2dae7950b42205eb718a46ee0c/lib/libisl.15.dylib
dyld: unloaded: /opt/software/packman.active/lib/libmpc.3.dylib
dyld: unloaded: /opt/software/packman.active/lib/libmpfr.4.dylib
dyld: unloaded: /opt/software/packman.active/lib/libgmp.10.dylib
dyld: Library not loaded: /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib
  Referenced from: /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
  Reason: Incompatible library version: f951 requires version 14.0.0 or later, but libgmp.10.dylib provides version 13.0.0
Trace/BPT trap: 5

1 个答案:

答案 0 :(得分:0)

我不明白为什么f951二进制文件会加载/opt/software/gmp/6.0.0a/0/lib/libgmp.10.dylib(版本13)而不是/opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib(版本14),这是用绝对路径指定的而不是亲戚@rpath

也许它是通过另一个库间接加载的,例如libisl.15.dylib,libmpc.3.dylib或libmpfr.4.dylib,它们可能有一个对libgmp.10.dylib的@rpath引用?

要诊断此问题,我建议你像这样运行主要的可执行文件:

$ DYLD_PRINT_RPATHS=YES /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951

这将打印所有rpath扩展(失败和成功),并可能会为您提供问题的答案。