缺少Haskell libclang绑定中的符号:clang_toggleCrashRecovery

时间:2011-05-13 12:59:54

标签: haskell linker clang

有一个libClang的错误,然后我用cabal安装它到最后我得到:

[13 of 13] Compiling Clang            ( src/Clang.hs, dist/build/Clang.o )
In file included from ./src/Clang/FFI_stub_ffi.h:6,

                 from src/Clang/FFI_stub_ffi.c:4:0: 

/usr/local/lib/ghc-7.0.3/include/HsFFI.h:29:0:
     warning: "__STDC_LIMIT_MACROS" redefined

<command-line>:0:0:
     note: this is the location of the previous definition
src/Clang/FFI_stub_ffi.c: In function ‘prim_getCString’:

src/Clang/FFI_stub_ffi.c:33:0:
     warning: assignment discards qualifiers from pointer target type
src/Clang/FFI_stub_ffi.c: In function ‘prim_toggleCrashRecovery’:

src/Clang/FFI_stub_ffi.c:2181:0:
     warning: implicit declaration of function ‘clang_toggleCrashRecovery’
Registering LibClang-0.0.9...

当我现在想用ghc编译一个使用Clang的脚本时我得到:

ghc --make test.hs -L.
[1 of 1] Compiling Main             ( test.hs, test.o )
Linking test ...
/home/foo/.cabal/lib/LibClang-0.0.9/ghc-7.0.3/libHSLibClang-0.0.9.a(FFI_stub_ffi.o): In function `prim_toggleCrashRecovery':
FFI_stub_ffi.c:(.text+0x1577): undefined reference to `clang_toggleCrashRecovery'
collect2: ld returned 1 exit status
某人知道该怎么做?

2 个答案:

答案 0 :(得分:3)

我可以在Arch Linux / x86_64上重现这个:我的libclang构建emits a warning关于缺少的符号,

src/Clang/FFI_stub_ffi.c:2181:1:
     warning: implicit declaration of function ‘clang_toggleCrashRecovery’ 
              [-Wimplicit-function-declaration]
Registering LibClang-0.0.9...
Installing library in /home/dons/.cabal/lib/LibClang-0.0.9/ghc-7.0.3
Registering LibClang-0.0.9...

并链接测试程序:

import Clang
main = print "yes"

失败了:

$ ghc --make A.hs
Linking A ...
/home/dons/.cabal/lib/LibClang-0.0.9/ghc-7.0.3/libHSLibClang-0.0.9.a(FFI_stub_ffi.o):
                In function `prim_toggleCrashRecovery':
FFI_stub_ffi.c:(.text+0x3513): undefined reference to `clang_toggleCrashRecovery'
collect2: ld returned 1 exit status

解决这些链接器错误的过程是识别该符号所在的C库存档。在我的libclang安装中搜索,我找不到这个符号:

$ find . -type f -exec grep  toggleCrashRecovery {} \;
$ grep toggleCrashRecovery /usr/lib/llvm/*
$ grep toggleCrashRecovery /usr/lib/llvm/*/*
zsh: no matches found: /usr/lib/llvm/*/*

这是一个线索,它可能只是在不同版本的libclang中可用的东西。我正在使用clang / llvm 2.9,有这个符号,而google确实会出现一些包含它的旧标题。所以我最好的猜测是这个符号在LLVM中不再可用,因此当前的haskell / libclang包依赖于LLVM / Clang 2.8。

解决方案:

下载libclang源代码,

$ cabal unpack libclang

并修补它以删除对toggle*函数的引用。

$ ghc --make A.hs
[1 of 1] Compiling Main             ( A.hs, A.o )
Linking A ...

补丁版本在此处:http://www.galois.com/~dons/tmp/LibClang-0.0.10.tar.gz

我也已将此信息转发给作者。

答案 1 :(得分:1)

感谢Don快速解决问题。 Hackage的最新版本修复了此问题: http://hackage.haskell.org/package/LibClang-0.1.0

请“cabal更新”,你应该好好去。 或者,您可以从https://github.com/chetant/LibClang

获取来源