有一个libClang的bug,然后我在我得到的最后用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有人知道该怎么做吗?
发布于 2011-05-14 01:25:01
我可以在Arch Linux /x86_64上重现这段代码:我的libclang build 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
我也把这个信息转发给了作者。
发布于 2011-05-15 03:43:21
谢谢Don的快速解决方案。此问题已在Hackage上的最新版本中修复:http://hackage.haskell.org/package/LibClang-0.1.0
请“阴谋更新”,你应该可以走了。或者,您可以从https://github.com/chetant/LibClang获取源代码
https://stackoverflow.com/questions/5992202
复制相似问题