2014-12-05 52 views
7

编译二进制文件时,我观察到两台机器之间的不同链接行为。什么决定了OS X上GHC的链接行为?

每个人都有同样的GHC(7.8.3),同样的代码,相同的标志(-Wall -O2),同样libgmp(由家酿每个安装):

machine-one$ otool -L my-binary 
my-binary: 
     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1) 
     /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0) 

machine-two$ otool -L my-binary 
my-binary: 
     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1) 
     /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0) 
     /usr/local/lib/libgmp.10.dylib (compatibility version 13.0.0, current version 13.0.0) 

我不能为我的生活弄清楚为什么libgmp在第二台机器上动态链接。

就差异而言,我已经认识到:通过第一台机器上的binary distribution for OS X和第二台上的Homebrew安装了GHC。对于C编译器,我们有:

machine-one$ cc --version 
Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn) 
Target: x86_64-apple-darwin13.4.0 
Thread model: posix 

machine-two$ cc --version 
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn) 
Target: x86_64-apple-darwin13.4.0 
Thread model: posix 

什么通常决定链接行为,以及如何执行一个链接方法或其他?

编辑:我发现在另一台机器上发生了与zlib相同的行为,所以它不是GMP特有的问题。

编辑:我弹拨从每台机器的ghc --info,在这里,他们是machine onemachine two。这两者之间的the diff也是如此。

编辑:我已经通过了二进制分发重新安装机器两个在GHC,果然libgmp当我重新编译的二进制我的动态链接。所以这似乎与通过Homebrew安装GHC有关。

对于究竟发生了什么仍然很感兴趣。

+0

我想这可能部分取决于GHC是如何编译的。你使用的两个发行版可能是以不同的方式编译的吗? – dfeuer 2014-12-05 20:07:02

+0

类似的问题:[(link)](http://stackoverflow.com/questions/10539857/statically-link-gmp-to-an-haskell-application-using-ghc-llvm)这可能会有所帮助。 – ErikR 2014-12-05 20:07:21

+0

@dfeuer GHC确实以不同的方式安装 - 通过二进制与通过自制软件 - 但我无法找到任何信息,无论在哪种情况下, @ user5402我知道无法传递OS X上的静态链接标志,因为无法静态链接libSystem和libiconv。 – jtobin 2014-12-05 20:44:11

回答

1

关键的区别在于机器#2在链接器路径中有/usr/local/lib,并且正在使用brew的链接器(/usr/local/Library/ENV/4.3/ld)。 ghc仍然使用外部链接器,即使它没有使用C后端进行代码生成,所以您可以将Haskell代码与其他语言编写的代码(Haskell与第三方库的许多FFI绑定关键)结合使用。所以你真的应该问酿造人为什么事情有不同的联系。这实际上不是ghc问题。

相关问题