Stack --ghc-options usage

I’m trying to run the following (based on this):

stack build \
  --ghc-options '-fPIC -O3 -static -optl-static -optl-pthread' \
  --docker --docker-image "utdemir/ghc-musl:v17-ghc8104" \

But it keeps saying recompile with -fPIC, even though it’s in the list of options.

If I try with just --ghc-options -fPIC then it works, but then it’s not using the other options.

I’ve tried various permutations (--ghc-options before every option, reordering the options, a space at the beginning of the string, an = after --ghc-options) but haven’t found one that actually works.

1 Like

I have a build command which seems to be working for my particular case, and there I’ve listed “-fPIC” at the very end of the --ghc-options string.

(I’m not entirely sure why I have that option on, but it’s presumably because stack/cabal told me to add it. I do have to list all the libraries to link explicitly, though. I don’t that particular problem has anything to do with the -fPIC handling.)

EDIT: I should also say: I’m building inside a custom alpine Docker image (less magic that way) and not using the --docker, etc. options for stack.

Do you get different results with the options moved to ghc-options in a package.yaml or .cabal file?