Template Haskell / GHCi does not respect extra-lib-dirs
In particular when compiling on NixOS, but also in many other situations, it is often needed to pass --extra-lib-dirs / --extra-include-dirs to cabal/stack, to help GHC find required system libraries. This works fine for GHC, but not GHCi, and therefore also not Template Haskell code.
Minimal example attached. Try it in an environment where libz is not in a standard location, e.g. inside a nix-shell. Note that if you remove the template Haskell splice in Main.hs, the code compiles just fine.
This affects GHC 7.10.2, but also HEAD from 2015-08-28, even one including Tamar Christina's 5d841108 commit cherry-picked. I haven't been able to test more recent HEAD, because of unrelated compilation issues.
I surmise that a fix to #10458 (closed), which currently blocks using HaskellR in GHCi, would also fix this, but I'm not sure. The error message I get is different:
$ stack build --skip-ghc-check --extra-lib-dirs=/nix/store/31w31mc8immhpnmxvcl4l0fvc3i5iwh0-zlib-1.2.8/lib --extra-include-dirs=/nix/store/31w31mc8immhpnmxvcl4l0fvc3i5iwh0-zlib-1.2.8/include b-0.1.0.0: build Preprocessing executable 'b' for b-0.1.0.0... [2 of 2] Compiling Main ( src/Main.hs, .stack-work/dist/x86_64-linux/Cabal-188.8.131.52/build/b/b-tmp/Main.o ) <command line>: can't load .so/.DLL for: libz.so (libz.so: cannot open shared object file: No such file or directory) -- While building package b-0.1.0.0 using: /home/mboes/.stack/setup-exe-cache/setup-Simple-Cabal-184.108.40.206-x86_64-linux-ghc-7.11.20150828 --builddir=.stack-work/dist/x86_64-linux/Cabal-220.127.116.11/ build exe:b --ghc-options " -ddump-hi -ddump-to-file" Process exited with code: ExitFailure 1