4

When I use both ghci with -fobject-code and command-line ghc, code is compiled fully when switching from one to the other. For example, when I work interactively in Emacs using haskell inferior mode configured to use cabal repl, code loads and compiles fine. Then I do a cabal build and same code is recompiled.

How can I prevent this double compilation assuming -fobject-code in ghci actually uses the same kind of binary format than ghc does?

3
  • 1
    I don't know about ghc-mod, but GHC defaults to storing compiles code next to source code, whereas Cabal puts the compiled code in the distribution folder... Sep 24, 2015 at 11:14
  • Actually, I talk about ghc-mod but I was wrong: I am using haskell-mode with embedded REPL which uses cabal repl under the hood.
    – insitu
    Sep 24, 2015 at 12:28
  • 1
    @insitu, please edit the correction into the question.
    – dfeuer
    Sep 24, 2015 at 15:23

2 Answers 2

2

You can have ghci and friends use different suffixes for the compiled files. Add the following to your ~/.ghci:

:set -hisuf i_hi
:set -osuf i_o

...and ghci will output stuff to foo.i_hi and foo.i_o which won't overwrite the .hi and .o files of ghc.

2

One workaround to this issue (seven years late, sorry! I'm putting it here in case someone finds it by Google) is the following:

Don't use -fobject-code in your GHCi flags, and instead specify -osuf dyn_o -hisuf dyn_hi. Doing this will get GHCi to opportunistically load object code built with -dynamic-too when available, and otherwise interpret the code.

Practically: cabal repl lib:sample --ghc-options "-osuf dyn_o -hisuf dyn_hi".

See the GHC bug "ghci no longer loads dynamic .o files" for more details: https://gitlab.haskell.org/ghc/ghc/-/issues/13604

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.