Haskell: How to only generate .hi file with ghc?

2019-02-14 07:30发布

I would like to generate an .hi interface file and only that (no object file, no code generation at all).

I tried

ghc -fno-code -ohi out.hi myfile.hs

and get

ghc: -ohi can only be used when compiling a single source file

which I don't understand since I have only given a single source file.

标签: haskell ghc
2条回答
戒情不戒烟
2楼-- · 2019-02-14 08:08

Around 2014, there was an option added to GHC specifically for this. Now, you can invoke:

ghc -fno-code -fwrite-interface ...

It actually speeds up compilation by about a quarter in some cases.

查看更多
Deceive 欺骗
3楼-- · 2019-02-14 08:23

Use -c option, or else ghc wants to link, not just to compile:

ghc -fno-code -ohi out.hi -c myfile.hs

UPDATE: but it doesn't really help, because -fno-code prevents .hi creation.

ghc -o /dev/null -ohi out.hi -c myfile.hs

This one throws away the result of compilation. However, it will also avoid unnecessary compilation if out.hi is up to date.

查看更多
登录 后发表回答