Sealing up your Haskell library inside a DLL is quite straightforward; compile up the object files that make up the library, and then build the DLL by issuing the following command:
ghc --mk-dll -o HSsuper.dll A.o Super.o B.o libmine.a -lgdi32 |
By feeding the ghc compiler driver the option --mk-dll, it will build a DLL rather than produce an executable. The DLL will consist of all the object files and archives given on the command line.
A couple of things to notice:
Since DLLs correspond to packages (see Section 3.7.4.1) you need to use -package-name dll-name when compiling modules that belong to a DLL. If you don't, Haskell code that calls entry points in that DLL will do so incorrectly, and a crash will result.
By default, the entry points of all the object files will be exported from the DLL when using --mk-dll. Should you want to constrain this, you can specify the module definition file to use on the command line as follows:
ghc --mk-dll -o .... -optdll--def -optdllMyDef.def |
EXPORTS DllCanUnloadNow = DllCanUnloadNow@0 DllGetClassObject = DllGetClassObject@12 DllRegisterServer = DllRegisterServer@0 DllUnregisterServer = DllUnregisterServer@0 |
In addition to creating a DLL, the --mk-dll option will also create an import library. The import library name is derived from the name of the DLL, as follows:
DLL: HScool.dll ==> import lib: libHScool_imp.a |