Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C2HS生成的C绑定中的链接器错误_C_Haskell_Ffi_C2hs - Fatal编程技术网

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
给出了我认为相同的错误,我编辑了这个问题