如何阻止GHC生成中间文件?

发布于 2024-08-04 16:26:45 字数 265 浏览 2 评论 0原文

当通过 ghc --make foo.hs 编译 haskell 源文件时,GHC 总是留下除 foo.exe 之外的各种中间文件。它们是 foo.hifoo.o

我经常不得不删除 .hi 和 .o 文件以避免文件夹混乱。

GHC 是否有一个命令行选项可以不留下中间文件? (当在 #haskell 上询问时,我得到的最佳答案是 ghc --make foo.hs && rm foo.hi foo.o 。

When compiling a haskell source file via ghc --make foo.hs GHC always leaves behind a variety of intermediate files other than foo.exe. These are foo.hi and foo.o.

I often end up having to delete the .hi and .o files to avoid cluttering up the folders.

Is there a command line option for GHC not to leave behind its intermediate files? (When asked on #haskell, the best answer I got was ghc --make foo.hs && rm foo.hi foo.o.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(6

哥,最终变帅啦 2024-08-11 16:26:45

我已经浏览了一些 GHC 文档,似乎没有一种内置方法可以自动删除临时文件——毕竟,GHC 需要这些中间文件来构建最终的可执行文件,并且它们的存在速度当 GHC 知道它不必重新编译模块时,进行整体编译。

但是,您可能会发现设置-outputdir option会帮助你;这会将所有目标文件 (.o)、接口文件 (.hi) 和 FFI 存根文件放置在指定目录中。它仍然“混乱”,但至少它不再位于您的工作目录中。

I've gone through the GHC docs a bit, and there doesn't seem to be a built-in way to remove the temporary files automatically -- after all, GHC needs those intermediate files to build the final executable, and their presence speeds up overall compilation when GHC knows it doesn't have to recompile a module.

However, you might find that setting the -outputdir option will help you out; that will place all of your object files (.o), interface files (.hi), and FFI stub files in the specified directory. It's still "clutter," but at least it's not in your working directory anymore.

对风讲故事 2024-08-11 16:26:45

GHC 现在有选项 no-keep-hi -filesno-keep-o-files请参阅此处了解更多信息。

GHC now has the options no-keep-hi-files and no-keep-o-files. See here for more information.

╰つ倒转 2024-08-11 16:26:45

我通常的工作流程是直接使用 cabal 而不是 ghc。这会将outputdir选项设置到适当的构建文件夹中,并且可以为您执行诸如构建haddock文档之类的操作。您所需要做的就是为您的项目定义 .cabal 文件,然后说 cabal install 或 cabal build 而不是直接运行 ghc。由于如果您想分享您的 hackage 工作,最终需要遵循此过程,因此这是一个很好的实践,并且它也有助于管理包依赖项。

My usual workflow is to use cabal rather than ghc directly. This sets the outputdir option into an appropriate build folder and can do things like build haddock documentation for you. All you need is to define the .cabal file for your project and then say cabal install or cabal build instead of run ghc directly. Since you need to follow this process in the end if you ever want to share your work on hackage, it is a good practice to get into and it helps manage package dependencies as well.

噩梦成真你也成魔 2024-08-11 16:26:45

我认为您可以将 -hidir 设置为 /dev/null,将它们发送到那里。此外,-fno-code 选项通常会关闭大量输出。您可能只想使用 Cabal。

You can set the -hidir to /dev/null, I think, sending them there. Also, the -fno-code option in general turns off a lot of output. You might just want to use Cabal.

你是我的挚爱i 2024-08-11 16:26:45

事实证明,使用 -hidir/-odir/-outputdir 是不好的; /dev/null 是一个文件,而不是一个目录。请参阅http://www.haskell.org/pipermail/xmonad/2010 -May/010182.html

Turns out that using -hidir/-odir/-outputdir is no good; /dev/null is a file, and not a directory. See http://www.haskell.org/pipermail/xmonad/2010-May/010182.html

永不分离 2024-08-11 16:26:45

2 美分即可稍微改进工作流程:
我们可以将以下别名放入 .bashrc (或类似的)配置中
文件:

alias hsc='_hsc(){ ghc -no-keep-hi-files -no-keep-o-files "$@";}; _hsc'

然后调用

$ hsc compose.hs 
[1 of 1] Compiling Main             ( compose.hs, compose.o )
Linking compose ...
$ ls
compose  compose.hs

2 cents to improve the workflow a bit:
We can put the following alias into the .bashrc (or similar) config
file:

alias hsc='_hsc(){ ghc -no-keep-hi-files -no-keep-o-files "$@";}; _hsc'

And then just call

$ hsc compose.hs 
[1 of 1] Compiling Main             ( compose.hs, compose.o )
Linking compose ...
$ ls
compose  compose.hs
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文