试图为C导出Haskell库

时间:2015-10-22 02:25:54

标签: c haskell

我在the Haskell FFI guide中复制了示例代码,作为将Haskell程序导出为C库的第一步,但无法进行编译。我有foo.hs

module Foo where
foreign export ccall foo :: Int -> IO Int

foo :: Int -> IO Int
foo n = return (length (f n))

f :: Int -> [Int]
f 0 = []
f n = n:(f (n-1))

这次成功汇编为foo_stub.hfoo_stub.o。这是foo_stub.h

#include "HsFFI.h"
#ifdef __cplusplus
extern "C" {
#endif
extern HsInt foo(HsInt a1);
#ifdef __cplusplus
}
#endif

但是我的C程序没有编译:

#include "foo_stub.h"
main() { foo(1); } // I realize this is probably wrong, and would also like advice on doing this part correctly, but note the error is not here.

错误:

gcc foo.c
In file included from foo.c:1:0:
foo_stub.h:1:19: fatal error: HsFFI.h: No such file or directory
 #include "HsFFI.h"
                   ^
compilation terminated.

我认为我错过了一些头文件,或者没有正确指向gcc。如有必要,我可以提供更多信息。关于如何解决这个问题的任何想法?

1 个答案:

答案 0 :(得分:3)

我找到了" HsFFI.h"在/usr/local/lib/ghc-7.10.2/include/HsFFI.h。您应该能够使用-I选项指示GCC查找。更多信息here