Pragmas for FFI imports

Einar Karttunen ekarttun at
Tue Feb 21 09:13:17 EST 2006

On 21.02 11:50, Duncan Coutts wrote:
> I'd just like to note that this shouldn't be the only way to specify
> this info. For many real FFI bindings we don't know the right search
> paths, defines, libs, lib link-time search paths, lib runtime search
> paths etc until we start configuring on the target system. (Though we do
> almost always know statically the names of the header files). This
> information is often obtained from pkg-config and other similar
> foo-config programs.

Yes, both -I and -L options can vary across machines and they
can be supported by Cabal. The name of the library is static
for most the simple cases and for the rest one usually
ends up using autoconf etc.

Of course with CPP there is a way to generate the pragmas
dynamically, but this is not something I would advertise.

> This information is not universally static. It depends on the machine
> were looking at. So it can't be embedded in .hs files. Current practise
> is to grok the output of pkg-config and generate the .cabal file at
> configure time. Cabal then passes all this info to ghc on the command
> line.

But it is not possible to have e.g.
Foo.Bar.MySQL (depends on -lmysql)
Foo.Bar.PgSQL (depends on -lpq)

and with suitable optional compiler support create an executable
that depends only on those libraries that it actually uses. This
is not possible if library dependencies are per-package. Of course
compilers can still default to actually handling dependencies
on a per package level if they want without breaking anything.

- Einar Karttunen

More information about the Haskell-prime mailing list