我在哪里可以找到(并运行)使用cabal沙箱编译的可执行文件?

时间:2015-02-13 14:49:58

标签: haskell testing compilation executable cabal

我使用cabal沙箱(使用myProgram.lhs设置)编译我的cabal sandbox init。我使用了一种最简单的方法:

cabal exec -- ghc myProgram

或(Makefile中有规则)

cabal exec -- make myProgram

之后,在我的源目录中,显示myProgram.o,但不显示可执行文件myProgram

如何运行生成的程序?

cabal exec -- ./myProgram

不起作用。

现在,我已经提出了一种最简单的方法来测试它:

cabal exec -- runghc myProgram.lhs

但我不喜欢这样。

您知道生成的可执行文件的位置吗?

(我还没有为我的项目创建任何cabal文件。我只是用裸ghc编译程序并测试它,然后 - 当我需要自定义依赖项时 - 我设置cabal sanbox并在那里手动安装了依赖项。)

1 个答案:

答案 0 :(得分:1)

这实际上看起来不像cabal exec的问题,而且它不是!

我的历史

在开始使用cabal沙箱的同时,我在源文件(myProgram.lhs)中明确地为我的模块提供了一个自定义名称。在这种情况下,只有裸ghc(没有cabal exec)也不会生成可执行文件,如Cabal output is redirected but not generated中所述。 (我根本无法测试裸ghc命令,因为我在沙箱中有依赖项,所以我的模块不会编译。)

解释

引自that Q&A的说明:

  

我收到了警告

output was redirected with -o, but no output will be generated because there is no main module.
     

Haskell 98报告引用:

A Haskell program is a collection of modules, one of which, by convention, must be called Main and must export the value main.

解决方案

解决方案是将-main-is MyProgram.main添加到ghc opts。然后它生成可执行文件。

./myProgram现在只是出现在我的源目录中,无论我是否打电话

ghc -main-is MyProgram.main myProgram

cabal exec -- ghc -main-is MyProgram.main myProgram