When compiling with the --hugs option on, a .c
file is generated, as well as a .hs file. Before the
Haskell stubs can be loaded by Hugs, you'll have to compile
up the .c stubs into a dynamically loadable library.
The details of how this is done differs from platform to platform, but here's an outline of how to do it on platforms using ELF (e.g., modern versions of Linux) and Win32. Under ELF, it's just a matter of generating a little bit of position-independent code:
gcc -fPIC -shared -o MyModule.so MyModule.c -Ihdirect/dir
A couple of things to note about this:
-fPIC -shared to generate a
dynamically loadable library - standard stuff, really.
#include of
the header file HDirect.h, which is supplied with
the HaskellDirect distribution. So, you'll need to use
the -I option to tell the C compiler where to find
it.-l and -L
options to satisfy the linker ; exactly which ones depend
on what library the generated stubs help you interface
to.On the Win32 side, the extension module can be created using Microsoft Visual C++
cl /nologo /LD /MD -o MyModule.dll MyModule.c -Ihdirect/dir
which also needs to be pointed at the directory containing the
HDirect.h header file.
Alternatively on Win32 platforms, you can use mingw32 as
supplied by the Cygwin toolchain distribution, for example:
c:\example> gcc -mno-cygwin -o MyModule.o MyModule.c -Ihdirect/dir
c:\example> dllwrap -mno-cygwin --target=i386-mingw32 \
--def HugsExt.def MyModule.o -o MyModule.dll
HugsExt.def is the module definition file, and contains
the following two lines:
EXPORTS
initModule
This .def file isn't supplied, so you'll have to type it all
in yourself.
As in the ELF case, both the VC++ and mingw32 route will in all likelihood require you to augment the command-lines in order to satisfy the linker.