C2HS生成的C绑定中的链接器错误
我使用C2HS生成的C绑定中的链接器错误,c,haskell,ffi,c2hs,C,Haskell,Ffi,C2hs,我使用 C->Haskell编译器,版本0.25.2 Snowboundest,2014年10月31日 构建平台是“x86_64-darwin”;生成命令: c2hs Structs.chs ghci Structs.hs 但是链接器抱怨说 During interactive linking, GHCi couldn't find the following symbol: get_foo 问:这是为什么?我如何解决?提前Thx A:tl;博士:我没有把.c编译成.o对象代码,是吗 代码如
C->Haskell编译器,版本0.25.2 Snowboundest,2014年10月31日
构建平台是“x86_64-darwin”
;生成命令:
c2hs Structs.chs
ghci Structs.hs
但是链接器抱怨说
During interactive linking, GHCi couldn't find the following symbol: get_foo
问:这是为什么?我如何解决?提前Thx
A:tl;博士:我没有把.c编译成.o对象代码,是吗
代码如下:
结构
modulemain其中
进口国外
进口外国货
#包括“Structs.h”
{#指针*foo作为foo}
{{#fun get_foo{`Int}->`foo'return*}
main::IO()
main=do
富奥富奥
得到富普=
获取(来自积分p)
main::IO()
main=do
foo在Structs.C
中定义了get\u foo
C函数,因此您需要将其提供给GHC。这应该奏效:
gcc -o Structs_c.o -c Structs.c
ghc --make Structs.hs Structs_c.o
对于GHCi,我认为您可以只说GHCi Structs.hs Structs\u c.o
。但是您肯定需要C对象文件 当使用GHC构建时(即不使用GHCi加载,但转换为适当的可执行文件)它是否工作?GHC--make Structs.hs
给出了我认为相同的错误,我编辑了这个问题