我在哪里可以找到(并运行)一个用cabal沙箱编译的可执行文件? [英] Where do I find (and run) an executable compiled with a cabal sandbox?

查看:167
本文介绍了我在哪里可以找到(并运行)一个用cabal沙箱编译的可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编译我的 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 )也不会生成可执行文件,在 Cabal输出已重定向但未生成。 (我只是无法测试裸露的 ghc 命令,因为我在沙箱中有依赖关系,所以我的模块不能编译。)



说明



引用的解释说明Q& A


我收到警告

 输出用-o重定向,但由于没有主模块,因此不会生成输出。 

来自Haskell 98 Report的报价:

  Haskell程序是一个模块集合,其中一个按惯例必须被称为Main,并且必须导出值main。 




解决方案



解决方案是将 -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:

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.

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沙箱编译的可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆