我正在使用 cabal 沙箱(使用 cabal sandbox init
设置)编译我的 myProgram.lhs
。我正在使用我想出的最简单的方法:
cabal exec -- ghc myProgram
或者(在Makefile
中有一个规则)
cabal exec -- make myProgram
之后,在我的源目录中,出现myProgram.o
,但不是可执行文件myProgram
。
如何运行生成的程序?
cabal exec -- ./myProgram
不起作用。
现在,我想出了一个最简单的方法来测试它:
cabal exec -- runghc myProgram.lhs
但我不喜欢这样。
你知道生成的可执行文件在哪里吗?
(我还没有为我的项目创建任何 cabal 文件。我只是用简单的 ghc
编译程序并测试它,然后——当我需要自定义依赖项时——我设置启动 cabal sanbox 并在那里手动安装依赖项。)
最佳答案
这实际上看起来不像是 cabal exec
的问题,事实也确实如此!
我的历史
在开始使用 cabal 沙箱的同时,我在源文件 (myProgram.lhs
) 中明确地为我的模块指定了一个自定义名称。在这种情况下,只有一个简单的 ghc
(没有 cabal exec
)也不会生成可执行文件,如 Cabal output is redirected but not generated 中的回答。 . (我根本无法测试裸露的 ghc
命令,因为我在沙箱中有依赖项,所以我的模块无法编译。)
说明
解释自that Q&A :
I get the warning
output was redirected with -o, but no output will be generated because there is no main module.
A quote from The Haskell 98 Report:
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
关于haskell - 我在哪里可以找到(并运行)用 cabal 沙箱编译的可执行文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28502176/