haskell——如何从非主模块创建二进制文件?

发布于 2024-12-13 20:12:26 字数 273 浏览 4 评论 0原文

我经常遇到在测试中留下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

想你的星星会说话 2024-12-20 20:12:26
ghc --make -main-is Test.Haar Test.Haar
ghc --make -main-is Test.Haar Test.Haar
对风讲故事 2024-12-20 20:12:26

但请注意,使用 -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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文