Problem exporting Haskell to C via a DLL in GHC 6.6
brianh at metamilk.com
Thu Feb 8 18:07:54 EST 2007
Simon Peyton-Jones wrote:
> I don't think there is any reason in principle why GHC can't generate
> DLLs that "just work", but plainly it's deficient at the moment.
The fundamental reason is that the DLL mechanism itself doesn't allow
initialization/ shutdown do be hidden from the user of a DLL, because the
order of loading/unloading DLLs is unspecified by the MS Windows operating
system. Therefore it's not a GHC problem - it's just a fact of life with
> The other thing is that we could do with more "how to" documentation
> about GHC and DLLs. We have a bit here:
> Could you expand it in the light of your experience?
I've added a section
which attempts to explain why init/exit code can't be put in DllMain, as
well as an *untested* example to show what I meant by putting init/exit code
in Begin/End functions instead.
I've put a note next to the example to say that it's untested, and to appeal
to anyone with more knowledge of static linking between Haskell and C to fix
anything I've missed or replace with a better example. (Apologies for not
testing it but static linking to stubs generated by GHC seems to require the
DLL to be compiled by gcc and use of gcc on Windows seems to require Cygwin
since gcc doesn't seem to understand Windows paths and I don't have Cygwin
installed - unfortunately at the moment I don't have time to pursue this
Best regards, Brian.
More information about the Glasgow-haskell-users