Haskell libclang 绑定中缺少符号:clang_toggleCrashRecovery

发布于 2024-11-07 17:02:16 字数 1221 浏览 8 评论 0原文

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

有人知道该怎么做吗?

have a bug with libClang, then i install it with cabal at the end i get:

[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...

when i now want to compile a script with ghc that uses Clang i get:

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

someone a idea what to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

攀登最高峰 2024-11-14 17:02:16

我可以在 Arch Linux / x86_64 上重现此内容:我的 libclang 版本发出关于缺少符号的警告

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

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

I can reproduce this on Arch Linux / x86_64: my libclang build emits a warning about the missing symbol,

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...

and linking a test program:

import Clang
main = print "yes"

fails with:

$ 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

The process of solving these kind of linker errors is to identify which C library archive that symbol lives in. Searching in my libclang install, I can't find this symbol:

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

which is a clue that it might be something only available in a different version of libclang. I'm using clang/llvm 2.9, which does not have this symbol, while google does turn up some older headers that do include it. So my best guess is that this symbol is no longer available in LLVM, and thus the current haskell/libclang package depends on LLVM/Clang 2.8.

Solution:

Download the libclang source,

$ cabal unpack libclang

and patch it to remove references to the toggle* functions.

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

A patched version is here: http://www.galois.com/~dons/tmp/LibClang-0.0.10.tar.gz

I've also forwarded this info to the author.

漫雪独思 2024-11-14 17:02:16

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

请“cabal update”,你就可以开始了。
或者,您可以从 https://github.com/chetant/LibClang 获取源代码

Thanks Don for the quick fix.
This issue is fixed with the latest version on Hackage:
http://hackage.haskell.org/package/LibClang-0.1.0

Please "cabal update" and you should be good to go.
Alternatively, you could get the source from https://github.com/chetant/LibClang

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文