How to specify dependency on external C library in .cabal?
The pkg-config method is preferable because pkg-config knows where to find include and library files, which may be in nonstandard locations on some systems.
You can write the .cabal file to use both methods. Using a flag, as shown here, has the advantage that Cabal will automatically try the other flag value if the default fails. (Below example is not tested)
Flag UsePkgConfig Description: Use pkg-config to check for library dependences Default: TrueExecutable hax if flag(UsePkgConfig) PkgConfig-Depends: libfoo >= 1.2 else Includes: foo.h Extra-libraries: foo
pkg-config
is not included in the Haskell Platform, nor could I imagine that it ever would be.
Usually I will use includes/Extra-libraries
if they're relatively simple. But for complex packages that may have a lot of included libraries, such as gtk, it's much nicer to use pkg-config when available.
It is possible to write a .cabal file that will work with and without specific fields. Try this:
if os(windows) Includes: foo.h Extra-libraries: fooelse PkgConfig-Depends: libfoo >= 1.2
Also note that .cabal
can run a configure script, which can help in some situations but isn't very windows-friendly.