I wanted to do some profiling on a Haskell application so in my hpack I added some ghc-options:
example-executable:
source-dirs: src
main: Main.hs
ghc-options:
- -O2
- -prof
- -fprof-auto
- -rtsopts
that resulted in this error:
[ 6 of 19] Compiling Model.Server ( src/Model/Server.hs, dist/build/discord-app-prof/discord-app-prof-tmp/Model/Server.o )
<no location info>: error:
src/Model/Server.hs:125:13: fatal:
Cannot load -prof objects when GHC is built with -dynamic
To fix this, either:
(1) Use -fexternal-interpreter, or
(2) Build the program twice: once with -dynamic, and then
with -prof using -osuf to set a different object file suffix.
Where is this -dynamic coming from? I don't recall ever running into this issue before when profiling previously which is also strange. Also it's confusing when it says "GHC is built with -dynamic" - surely GHC is not being built here but the haskell executable?
I'm using GHC 9.0.2
A quick solution was to change my
default.nix, the-dynamicis probably being set as a default somewhere:As mentioned here: How can I enable Haskell profiling when using Nix's callCabal2nix