haskell——如何从非主模块创建二进制文件?
我经常遇到在测试中留下 main :: IO ()
函数的情况。我可以使用 runghc
很好地运行它们,但有时我想编译它们(例如在另一个平台上运行)。有办法做到这一点吗?例如,如果我运行,
ghc --make Test.Haar
其中 Test/Haar.hs
有一个 main
方法,那么什么也不会发生,它只是创建 .o
文件。
I often have situations where I leave main :: IO ()
functions in tests. I can run these fine with runghc
, but sometimes I want to compile them (e.g. for running on another platform). Is there a way to do this? If I run, for example,
ghc --make Test.Haar
where Test/Haar.hs
has a main
method, then nothing happens, it just creates the .o
file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
但请注意,使用
-main-is Test.Haar
后,如果您想将该模块用作另一个程序的一部分,则必须在不带-main-is< 的情况下重新编译它。 /code>,否则链接器将找到两个入口点并抛出错误。
Note, however, that after using
-main-is Test.Haar
, if you want to use the module as part of another programme, you have to recompile it without the-main-is
, otherwise the linker will find two entry-points and throw an error.