[Haskell-cafe] Creating DLLs with GHC

SevenThunders mattcbro at earthlink.net
Wed Sep 27 16:28:45 EDT 2006

Jason Dagit wrote:
> On 9/26/06, Matthew Bromberg <mattcbro at earthlink.net> wrote:
>> I am having some difficulty with creating a dynamic link library using
>> GHC on windows XP.
>> I am attempting to follow the example in
>> http://www.haskell.org/ghc/docs/6.4/html/users_guide/win32-dlls.html
>> though I have a binary build of ghc 6.5
>> My problem (I think) is that some of my Haskell source files link to an
>> external C library also contained in a DLL.
>> I generate my Haskell object files when I compile my Haskell executable.
>> I then attempt to use the object files in a ghc compiler statement like
>> this,
>> ghc --mk-dll -o netsim.dll ExternLib.o ExternLib_stub.o dllNet.o src1.o
>> src1_stub.o src2.o  -optl-lmatrixstack -optl-L"."
>> My external C library is in matrixstack.dll and it has a corresponding
>> static link stub library matrixstack.lib in the same directory as all
>> the sources. It has references in one of the sources (say src1.hs).
>> Unfortunately I get a host of undefined references to basically all the
>> functions in matrixstack.dll and also some undefined references of the
>> form
>> Parsefile.o:ghc2996_0.hc:(.text+0x130): undefined reference to
>> `TextziParserCombinatorsziParsecziError_show_closure'
>> Parsefile.o:ghc2996_0.hc:(.text+0x220): undefined reference to
>> `TextziParserCombinatorsziParsecziChar_spaces_closure'
>> Parsefile.o:ghc2996_0.hc:(.text+0x24a): undefined reference to
>> `TextziParserCombinatorsziParsecziChar_spaces_closure'
>> Parsefile.o:ghc2996_0.hc:(.text+0x29c): undefined reference to
>> `TextziParserCombinatorsziParsecziChar_spaces_closure'
>> ...
> If you use cabal I think can follow an example I put on the wiki to
> get these undefined references to go away:
> http://www.haskell.org/haskellwiki/Cabal
> Jason
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

Does cabal really work on windows?  Although it's installed I notice that
when I try to build my library using it, it dies on the first foreign import
statement in the first .hs source it tries to compile. It is reminiscent of
trying to import a foreign C module directly ghci.  ghc.exe, on the other
hand has no problem with it.  

Does this scheme address the problem of being unable to link external C
libraries (a DLL) into the Haskell DLL?  Are there any other workarounds
here?  Is it possible to create static link libraries compatible with MS
VC++?  Ultimately I'm trying to link my C code with Matlab.  The C code stub
will then call a bunch of Haskell routines.

View this message in context: http://www.nabble.com/Creating-DLLs-with-GHC-tf2342692.html#a6534625
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

More information about the Haskell-Cafe mailing list