我复制了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.h
和 foo_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 指向它们。如有必要,我可以提供更多信息。关于如何解决此问题的任何想法?
最佳答案
我在 /usr/local/lib/ghc-7.10.2/include/HsFFI.h
找到了“HsFFI.h”。您应该能够使用 -I
选项指示 GCC 到那里查看。更多信息 here .
关于c - 尝试为 C 导出 Haskell 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33272417/