ffihugs [option...] [-i
include...] file [cc-arg...]
Any module that contains foreign import declarations must be compiled with ffihugs before it can be loaded into Hugs.
Suppose you have some C functions in test.c
with some foreign import declarations for those
functions in HTest.hs,
and that the code in test.c needs to be
compiled with -lm
.
To use these with Hugs, you must first use ffihugs
to generate HTest.c, compile it and link it against
test.c with -lm
to produce
an object file (HTest.so on Unix,
HTest.dll on Windows):
ffihugs HTest.hs test.c -lmAny Hugs options should be placed before the module name, as in
ffihugs -98 HTest.hs test.c -lmNow you can run Hugs as normal:
hugs -98 HTest.hsWhen HTest.hs is loaded, Hugs will load the corresponding object file and then use the imported functions. (If HTest.hs depends on other modules using foreign functions, you'll have to have compiled those modules too, but not necessarily before compiling HTest.hs.)
Note: Because ffihugs generates a C file with the same base name as the Haskell source file, any auxiliary C files should avoid that name.
In the standard FFI, each foreign import declaration should name a C header file containing the prototype of the function. Because this is often cumbersome, ffihugs provides the following additional option: