[英]Building with runtime flags using cabal and ghc
我有一个用 Haskell 编写的程序,打算用 GHC 编译。 该程序在多核上的扩展性非常好,因此启用多线程非常重要。 在我的.cabal
文件中,我添加了ghc-options: -O3 -threaded
以与线程运行时链接。 问题是,使用这种方法,用户需要使用foo +RTS -N
运行程序,这似乎有点神秘,而且对用户不太友好。
如何告诉 cabal/ghc 对用户不可见地启用这些运行时标志? 我已经阅读过--with-rtsopts
,但是当我尝试使用 GHC (7.0.3) 时,它只会吐出unrecognized flag
。
该标志是-with-rtsopts
,而不是--with-rtsopts
,因此您应该将-with-rtsopts=-N
添加到 ghc-options 字段。 GHC 标志参考。
请注意,这还需要您通过将-rtsopts
添加到 ghc-options 来链接运行时支持。
如果您碰巧使用hpack
从package.yaml
生成foo.cabal
,则使用 YAML 语法:
executables:
foobar:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- '"-with-rtsopts=-N -T"'
- -Wall
dependencies:
[…]
字符串"-with-rtsopts=-N␣-T"
应该成为最终ghc
进程的一个argv 项。
由于 YAML 也引用了字符串文字 - escaping 的两层都是必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.