GHC API, how to link to dynamically linked library

I use Arch Linux and all Haskell libraries are dynamically linked. So in order to compile Haskell codes, I need to add the -dynamic flag to the command and configure cabal to do it automatically.
I’ve been playing around with the GHC API, following these

The code itself runs, but always encounter the error
Could not find module ‘Prelude’
There are files missing in the ‘base-4.15.1.0’ package
which I recognize is the same error as that I get if I try to compile haskell without the -dynamic flag. I’ve tried configuring dflags but nothings fixed it. Any advice?

Someone who knows more will probably come by shortly and say “don’t use Arch packages for Haskell development, they are completely broken”. (I don’t know myself, but this is what I recall hearing repeatedly.)

1 Like

This doesn’t bode well for me

Well, you can install statically linked Haskell development tools on Arch by referring to the Haskell Downloads page.

Don’t use Arch packages for Haskell development, they’re completely broken. The reasons for this are outlined here by me: Haskell on Arch Linux in 2020

Your best bet in 2022 is to install ghcup and install ghc/cabal/hls through that. If you don’t want to use ghcup for some reason, the other options outlined in that blog post still work as alternatives.

6 Likes

Cases like what the poster here describes are very good examples of why Arch is broken btw. Even if regular compilation is configured to only do dynamic linking, many aspects hardwired into ghc for using the API and other things (template haskell, plugins, iirc) assume that the static library will also be available, and get very confused when this invariant is broken. Arch steadfastly refuses to recognize this situation.

2 Likes