【发布时间】:2014-03-27 17:51:41
【问题描述】:
我正在学习如何让 C++ 调用库中的 Haskell 代码,我按照 FFI 完整示例 http://www.haskell.org/haskellwiki/FFI_complete_examples 中的说明进行操作
然而,在
之后ghc -v Foo.hs
仅创建 Foo_stub.h 和 Foo.o,没有 Foo_stub.c 或 Foo_stub.o。根据Calling Haskell from C,ghc > 7.2 不再生成_stub.o。
在这种情况下,我是否还需要 stub.o 来链接一个可执行文件使用 g++?
之后的那一刻
g++ -o test Foo.o test.o `cat link_options`
hs_init 等出现很多未定义符号错误。是因为_stub.o 不存在还是缺少其他东西?
我可以使用 ghc 正确链接它们:
ghc -no-hs-main -o test test.o Foo.o -lstdc++
(看完这个问题:Building a dynamic library with haskell and using it from C++)
但我想知道是否仍然可以使用 g++ 进行链接?
【问题讨论】:
-
关于如何使
C和Haskell相处的任何提示?我在 NixOS 中有ghc 8.4.3。问题是一样的:没有 Foo_stub.c.