问题描述
我正在编译我的 myProgram.lhs
,并使用cabal沙箱(设置为 cabal sandbox init
)。我使用了最简单的方法:
cabal exec - ghc myProgram
code>
或(在
Makefile
中有一条规则)
cabal exec - make myProgram
之后,在我的源代码目录中,出现
myProgram.o
,但不是可执行文件 myProgram
p>
如何运行生成的程序?
cabal exec - 。 / myProgram
无效。
现在,我想出了一个最简单的方法来测试它:
cabal exec - runghc myProgram.lhs
但我不喜欢这个。
你知道生成的可执行文件的位置吗?
(我还没有为我的项目创建任何cabal文件,我只是用 ghc
并测试它,然后 - 当我需要自定义依赖关系时s - 我建立了cabal sanbox并在那里手动安装依赖项。)
解决方案这实际上并不像问题 cabal exec
,它不是!
我的历史记录
在开始使用cabal沙箱的同时,我在源文件( myProgram.lhs
)中明确给出了我的模块的自定义名称。在这种情况下,只有一个空的 ghc
(没有 cabal exec
)也不会生成可执行文件,在。 (我只是无法测试裸露的 ghc
命令,因为我在沙箱中有依赖关系,所以我的模块不能编译。)
说明
从:
解决方案
解决方案是将 -main-is MyProgram.main
添加到ghc opts。然后它会生成可执行文件。
./ myProgram
现在只出现在我的源代码目录中,不管我是否打电话
ghc -main-is MyProgram.main myProgram
或
cabal exec - ghc -main-是MyProgram.main myProgram
I'm compiling my myProgram.lhs
with the use of a cabal sandbox (set up with cabal sandbox init
). I'm using a simplest approach I've come up with:
cabal exec -- ghc myProgram
or (having a rule in Makefile
)
cabal exec -- make myProgram
After that, in my source directory, appears myProgram.o
, but not the executable myProgram
.
How do I run the resulting program?
cabal exec -- ./myProgram
doesn't work.
Now, I've come up with a simplest approach to test it:
cabal exec -- runghc myProgram.lhs
but I don't like this.
Do you know where the resulting executable is?
(I haven't created any cabal file for my project yet. I simply used to compile the program with bare ghc
and test it, then--when I needed custom dependencies--I set up the cabal sanbox and installed the dependencies manually there.)
解决方案 This didn't actually look like a problem of cabal exec
, and it wasn't!
My history
Simultaneously with starting to use the cabal sandbox, I explicitly gave a custom name to my module in the source file (myProgram.lhs
). And in such case just a bare ghc
(without cabal exec
) wouldn't generate the executable, too, as answered in Cabal output is redirected but not generated. (I simply couldn't test the bare ghc
command, because I had the dependencies in the sandbox, so my module wouldn't compile.)
Explanation
Explanation quoted from that Q&A:
The solution
A solution is to add -main-is MyProgram.main
to ghc opts. Then it generates the executable.
./myProgram
simply appears in my source directory now, no matter whether I call
ghc -main-is MyProgram.main myProgram
or
cabal exec -- ghc -main-is MyProgram.main myProgram
这篇关于我在哪里可以找到(并运行)一个用cabal沙箱编译的可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!