作为将 Haskell 程序导出为 C 库的第一步,我复制了Haskell FFI 指南中的示例代码,但无法编译。我有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))
Run Code Online (Sandbox Code Playgroud)
这成功编译到foo_stub.h
和foo_stub.o
。这是foo_stub.h
:
#include "HsFFI.h"
#ifdef __cplusplus
extern "C" {
#endif
extern HsInt foo(HsInt a1);
#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)
但后来我的 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.
Run Code Online (Sandbox Code Playgroud)
错误:
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.
Run Code Online (Sandbox Code Playgroud)
我假设我缺少一些头文件或者没有正确地将 gcc 指向它们。如有必要,我可以提供更多信息。有想法该怎么解决这个吗?