【发布时间】:2023-04-06 05:47:01
【问题描述】:
我有一个模块 (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 选项没有帮助。
相关问题
这是与 Testing FFI Code with GHCi 不同的问题,其中的重点是使用 C 库中的
foreign import(而不是export)测试 Haskell 代码。GHCi doesn't work with FFI export declarations/shared libaries 对我来说似乎很奇怪,因为它对我没有帮助。它处理从 Haskell 到 C 的
foreign export,但解决的问题是缺少一些目标文件。
【问题讨论】: