我有一个模块(Safe.hs
),其中包含以下内容:
foreign export ccall respond_hs :: CWString -> IO CWString
针对 C 的 FFI。
我想在 GHCi 中加载 Safe.hs
并对其中的一些内容进行评估。
但是,ghci
无法加载它(我正在指定两个源文件,因为它依赖于 valencies.lhs
):
$ ghci src/valencies.lhs src/Safe.hs
GHCi, version 7.6.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 2] Compiling Valencies ( src/valencies.lhs, interpreted ) [flags changed]
[2 of 2] Compiling Safe ( src/Safe.hs, interpreted )
src/Safe.hs:10:1:
Illegal foreign declaration: requires via-C, llvm (-fllvm) or native code generation (-fvia-C)
When checking declaration:
foreign export ccall "respond_hs" respond_hs
:: CWString -> IO CWString
Failed, modules loaded: Valencies.
*Valencies> :q
Leaving GHCi.
$
使用-fvia-C
选项并没有帮助。
相关问题
这不同于使用GHCi测试FFI代码的问题,那里的重点是使用C库中的
foreign import
(而不是export
)来测试Haskell代码。GHCi与FFI导出声明/共享库不兼容对我来说很奇怪,因为它没有帮助我。它处理了从Haskell到C的
foreign export
,但解决的问题是一些缺失的目标文件。