本文介绍了我如何在ghci中使用cabal的MIN_VERSION_和其他宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Haskell项目中使用Cabal的各种 MIN_VERSION _ 宏时,我如何确保当我不使用cabal时它们全部正确定义,例如当在GHCi中测试时?

解决方案

现在, cabal c $ c> cabal repl 子命令,它为你完成所有的设置,所以至少对于 ghci ,以下是不必要的。然而:
$ b

cabal build 命令生成文件 dist / build / autogen / cabal_macros .h ,它包含您需要的所有定义。为了将该文件包含在ghc调用中,您需要标记 -optP-include -optPdist / build / autogen / cabal_macros.h



为方便起见,您可以将以下内容放置在项目目录中的 .ghci 文件中:

 :set -optP-include -optPdist / build / autogen / cabal_macros.h 

,这样你就不必在每次使用ghci时输入选项。

请注意,当您上次运行 cabal build 时,宏将根据配置进行定义,并且在安装新程序包或使用其他GHC版本时不会更新:为此,需要重新配置和重建软件包。



(感谢Simon Hengel在这个智慧的库列表中:)。


When I use Cabal's various MIN_VERSION_ macros in a Haskell project, how can I ensure they are all correctly defined when I am not using cabal, e.g. when testing in GHCi?

解决方案

Nowadays, cabal supports a cabal repl subcommand, which does all the setup for you, so at least for ghci the following is unnecessary. Nevertheless:

The cabal build command generates the file dist/build/autogen/cabal_macros.h, which contains all the definitions you need. In order to include that file in a ghc invocation, you'll need the flags -optP-include -optPdist/build/autogen/cabal_macros.h.

For convenience, you can place the following in a .ghci file in the project directory:

:set -optP-include -optPdist/build/autogen/cabal_macros.h

so that you don't have to type out the options every time you want to use ghci.

Beware, though: the macros will be defined according to the configuration when you last ran cabal build, and will not be updated when you install new packages or use a different GHC version: for that you'd need to re-configure and rebuild the package.

(Thanks to Simon Hengel on the libraries list for this wisdom: http://www.haskell.org/pipermail/libraries/2012-September/018491.html).

这篇关于我如何在ghci中使用cabal的MIN_VERSION_和其他宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 03:54