Open nh2 opened 4 years ago
+1, I seem to be seeing this too, and the workaround does fix it.
Edit: For those interating on nixos or using a nix shell, since those paths are not even remotely constant, you might do as I did and define the CABAL_CONFIG env var in your shell derivation to be:
pkgs.writeText "config" ''
program-default-options
ghc-options: -L${lib.getLib <yourlibrary>} -l<yourlib>
'';
When you use
pkgconfig-depends
, Cabal determines-I
,-L
and-l
flags.Of those, only the
includDirs
are passed toghc --make
here (and related code below it):https://github.com/haskell/cabal/blob/09db4dc416c2ed5dd3e6fd4d38afa1db928f0a85/Cabal/src/Distribution/Simple/GHC/Internal.hs#L283
I believe that is insufficient, and the
-L
and-l
flags need to be passed.The reason:
import
ed. For example functionf
from moduleM
.f
may use foreign library code. Example: You call, at compile time, a functionf = generatePNG
that calls some C functiongenPNG()
fromlibpng
.-l
libraries from the-L
paths when loadingM
.Because
-l
/-L
are not passed toghc --make
, you'll get an error like this:Tragically, you get this error even if you don't make any use of that foreign code at compile time (e.g. you never need
generatePNG
at compile time, but only at run time), simply because GHC will try to satisfy all symbols when loadingM
, and then fail.Current workaround
Set
ghc-options: -L/path/to/mylib -lmylib
in your cabal file, in addition topkgconfig-depends: mylib
.This is bad, because you need to hardcode
-L/path/to/mylib
, and it varies across Linux distributionsProposed solution
Pass the
pkg-config
-determined-L
and-l
flags to GHC, in the same way as we do it with-I
flags.