Success Story: Cabal and Dlls

Hello, I would like to report that I was able to use Cabal with Visual Haskell to build Dlls in windows. I have posted the details about this on the Haskell wiki (and started an extremely minimal Cabal page). If my content is in the wrong place, please feel free to move it (or edit it or whatever). http://www.haskell.org/haskellwiki/Cabal The trick was to take the final HSfoo-0.1.o file generated by the normal build process (and linked with the DllMain.c code) and tell ghc to build a dll. I use -package with each of the dependencies in the cabal file to link with the needed libraries. The resulting dll seems to be working. This approach is a bit hackish and while I've tried to implement as much of it as I can in a general way it requires you to hack your Setup.lhs file if you want to 1) build static 2) specify your exports 3) specify the name of the resulting dll. Also, it's only been tested on my setup which uses Visual Haskell so it may not be fit for general consumption. Finally, I just started really looking at Cabal yestarday so I may not have considered things which an experienced Cabal user would think about. Is it possible to get this functionality built directly into Cabal so that I tell it I want a DLL built from a library and it knows how to make it happen? Thanks, Jason

Hi Jason,
I am using the same technique to build VSHaskell itself.
Cheers,
Krasimir
On 7/27/06, Jason Dagit
Hello,
I would like to report that I was able to use Cabal with Visual Haskell to build Dlls in windows. I have posted the details about this on the Haskell wiki (and started an extremely minimal Cabal page). If my content is in the wrong place, please feel free to move it (or edit it or whatever).
http://www.haskell.org/haskellwiki/Cabal
The trick was to take the final HSfoo-0.1.o file generated by the normal build process (and linked with the DllMain.c code) and tell ghc to build a dll. I use -package with each of the dependencies in the cabal file to link with the needed libraries. The resulting dll seems to be working.
This approach is a bit hackish and while I've tried to implement as much of it as I can in a general way it requires you to hack your Setup.lhs file if you want to 1) build static 2) specify your exports 3) specify the name of the resulting dll. Also, it's only been tested on my setup which uses Visual Haskell so it may not be fit for general consumption. Finally, I just started really looking at Cabal yestarday so I may not have considered things which an experienced Cabal user would think about.
Is it possible to get this functionality built directly into Cabal so that I tell it I want a DLL built from a library and it knows how to make it happen?
Thanks, Jason _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

Ah, when I was looking for information on doing this I didn't think to
check the Visual Haskell source. Perhaps I didn't think of it because
I have yet to get it building (but I think I've found a few things
that are probably easy to improve, for example, when the .cabal file
has a syntax error Visual Haskell doesn't report the error correctly).
If you get a chance I would appreciate it if you could look over the
code I posted on the wiki and try to improve it with your knowledge.
Thanks,
Jason
On 7/26/06, Krasimir Angelov
Hi Jason,
I am using the same technique to build VSHaskell itself.
Cheers, Krasimir
On 7/27/06, Jason Dagit
wrote: Hello,
I would like to report that I was able to use Cabal with Visual Haskell to build Dlls in windows. I have posted the details about this on the Haskell wiki (and started an extremely minimal Cabal page). If my content is in the wrong place, please feel free to move it (or edit it or whatever).
http://www.haskell.org/haskellwiki/Cabal
The trick was to take the final HSfoo-0.1.o file generated by the normal build process (and linked with the DllMain.c code) and tell ghc to build a dll. I use -package with each of the dependencies in the cabal file to link with the needed libraries. The resulting dll seems to be working.
This approach is a bit hackish and while I've tried to implement as much of it as I can in a general way it requires you to hack your Setup.lhs file if you want to 1) build static 2) specify your exports 3) specify the name of the resulting dll. Also, it's only been tested on my setup which uses Visual Haskell so it may not be fit for general consumption. Finally, I just started really looking at Cabal yestarday so I may not have considered things which an experienced Cabal user would think about.
Is it possible to get this functionality built directly into Cabal so that I tell it I want a DLL built from a library and it knows how to make it happen?
Thanks, Jason _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

Perhaps I spoke too soon.
I loaded my dll into a C++ application (where it will be used) and as
soon as I hit FreeLibrary() my program crashes. I tried adding
shutdownHaskell() to the dll and it gets a little better. It goes
from crashing all the time to crashing some of the time. I wrote a
small test program in C++ where I added a 100 iteration loop that just
loads and unloads the Dll. It seems to crash my program usually
before getting to the double digits. I noticed the memory usage seems
to climb quite a bit too.
I found this thread:
http://www.haskell.org//pipermail/glasgow-haskell-users/2006-March/009771.ht...
I don't see a solution listed there. This is a show stopper for me.
If I can't get Dlls working reliably then I won't be using haskell :(
So I'm looking for just about any reasonable solution.
Thanks,
Jason
On 7/26/06, Jason Dagit
Ah, when I was looking for information on doing this I didn't think to check the Visual Haskell source. Perhaps I didn't think of it because I have yet to get it building (but I think I've found a few things that are probably easy to improve, for example, when the .cabal file has a syntax error Visual Haskell doesn't report the error correctly).
If you get a chance I would appreciate it if you could look over the code I posted on the wiki and try to improve it with your knowledge.
Thanks, Jason
On 7/26/06, Krasimir Angelov
wrote: Hi Jason,
I am using the same technique to build VSHaskell itself.
Cheers, Krasimir
On 7/27/06, Jason Dagit
wrote: Hello,
I would like to report that I was able to use Cabal with Visual Haskell to build Dlls in windows. I have posted the details about this on the Haskell wiki (and started an extremely minimal Cabal page). If my content is in the wrong place, please feel free to move it (or edit it or whatever).
http://www.haskell.org/haskellwiki/Cabal
The trick was to take the final HSfoo-0.1.o file generated by the normal build process (and linked with the DllMain.c code) and tell ghc to build a dll. I use -package with each of the dependencies in the cabal file to link with the needed libraries. The resulting dll seems to be working.
This approach is a bit hackish and while I've tried to implement as much of it as I can in a general way it requires you to hack your Setup.lhs file if you want to 1) build static 2) specify your exports 3) specify the name of the resulting dll. Also, it's only been tested on my setup which uses Visual Haskell so it may not be fit for general consumption. Finally, I just started really looking at Cabal yestarday so I may not have considered things which an experienced Cabal user would think about.
Is it possible to get this functionality built directly into Cabal so that I tell it I want a DLL built from a library and it knows how to make it happen?
Thanks, Jason _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

Probably this is a bug in GHC or maybe not. In any case it will help
if you can find where is the problem. Alternatively you can try to
make as small as possible example and submit this as a bug.
Cheers,
Krasimir
On 7/27/06, Jason Dagit
Perhaps I spoke too soon.
I loaded my dll into a C++ application (where it will be used) and as soon as I hit FreeLibrary() my program crashes. I tried adding shutdownHaskell() to the dll and it gets a little better. It goes from crashing all the time to crashing some of the time. I wrote a small test program in C++ where I added a 100 iteration loop that just loads and unloads the Dll. It seems to crash my program usually before getting to the double digits. I noticed the memory usage seems to climb quite a bit too.
I found this thread: http://www.haskell.org//pipermail/glasgow-haskell-users/2006-March/009771.ht...
I don't see a solution listed there. This is a show stopper for me. If I can't get Dlls working reliably then I won't be using haskell :( So I'm looking for just about any reasonable solution.
Thanks, Jason
On 7/26/06, Jason Dagit
wrote: Ah, when I was looking for information on doing this I didn't think to check the Visual Haskell source. Perhaps I didn't think of it because I have yet to get it building (but I think I've found a few things that are probably easy to improve, for example, when the .cabal file has a syntax error Visual Haskell doesn't report the error correctly).
If you get a chance I would appreciate it if you could look over the code I posted on the wiki and try to improve it with your knowledge.
Thanks, Jason
On 7/26/06, Krasimir Angelov
wrote: Hi Jason,
I am using the same technique to build VSHaskell itself.
Cheers, Krasimir
On 7/27/06, Jason Dagit
wrote: Hello,
I would like to report that I was able to use Cabal with Visual Haskell to build Dlls in windows. I have posted the details about this on the Haskell wiki (and started an extremely minimal Cabal page). If my content is in the wrong place, please feel free to move it (or edit it or whatever).
http://www.haskell.org/haskellwiki/Cabal
The trick was to take the final HSfoo-0.1.o file generated by the normal build process (and linked with the DllMain.c code) and tell ghc to build a dll. I use -package with each of the dependencies in the cabal file to link with the needed libraries. The resulting dll seems to be working.
This approach is a bit hackish and while I've tried to implement as much of it as I can in a general way it requires you to hack your Setup.lhs file if you want to 1) build static 2) specify your exports 3) specify the name of the resulting dll. Also, it's only been tested on my setup which uses Visual Haskell so it may not be fit for general consumption. Finally, I just started really looking at Cabal yestarday so I may not have considered things which an experienced Cabal user would think about.
Is it possible to get this functionality built directly into Cabal so that I tell it I want a DLL built from a library and it knows how to make it happen?
Thanks, Jason _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

Jason Dagit wrote:
Perhaps I spoke too soon.
I loaded my dll into a C++ application (where it will be used) and as soon as I hit FreeLibrary() my program crashes. I tried adding shutdownHaskell() to the dll and it gets a little better. It goes from crashing all the time to crashing some of the time. I wrote a small test program in C++ where I added a 100 iteration loop that just loads and unloads the Dll. It seems to crash my program usually before getting to the double digits. I noticed the memory usage seems to climb quite a bit too.
I found this thread: http://www.haskell.org//pipermail/glasgow-haskell-users/2006-March/009771.ht...
I don't see a solution listed there. This is a show stopper for me. If I can't get Dlls working reliably then I won't be using haskell :( So I'm looking for just about any reasonable solution.
We do have some bugs with loading and unloading DLLs multiple times. I believe
I've fixed the worst bugs (the ones that cause direct crashes), but there are
apparently some resource leakages too.
The version of GHC you have with Visual Haskell doesn't have the fixes
unfortunately, so you would have to drop VH and use a GHC snapshot or wait until
we can put out a new Visual Haskell (no timeframe for that as yet).
See these:
http://hackage.haskell.org/trac/ghc/ticket/803
http://hackage.haskell.org/trac/ghc/ticket/804
http://hackage.haskell.org/trac/ghc/ticket/753
http://hackage.haskell.org/trac/ghc/ticket/747
http://hackage.haskell.org/trac/ghc/ticket/716
You should probably talk to Lennart Augustsson

On 7/27/06, Simon Marlow
The version of GHC you have with Visual Haskell doesn't have the fixes unfortunately, so you would have to drop VH and use a GHC snapshot or wait until we can put out a new Visual Haskell (no timeframe for that as yet).
Actually I am working on the next Visual Haskell release. It is working with the latest GHC snapshot and supports both VStudio 2003 & VStudio 2005. You can expect the new release candidate quite soon. Cheers, Krasimir

On 27 July 2006 12:37, Krasimir Angelov wrote:
On 7/27/06, Simon Marlow
wrote: The version of GHC you have with Visual Haskell doesn't have the fixes unfortunately, so you would have to drop VH and use a GHC snapshot or wait until we can put out a new Visual Haskell (no timeframe for that as yet).
Actually I am working on the next Visual Haskell release. It is working with the latest GHC snapshot and supports both VStudio 2003 & VStudio 2005. You can expect the new release candidate quite soon.
Yay! That's great news. Does that mean that we have fixed http://hackage.haskell.org/trac/ghc/ticket/756? Cheers, Simon

Yes. It is working well with the new threaded RTS.
On 7/27/06, Simon Marlow
On 27 July 2006 12:37, Krasimir Angelov wrote:
On 7/27/06, Simon Marlow
wrote: The version of GHC you have with Visual Haskell doesn't have the fixes unfortunately, so you would have to drop VH and use a GHC snapshot or wait until we can put out a new Visual Haskell (no timeframe for that as yet).
Actually I am working on the next Visual Haskell release. It is working with the latest GHC snapshot and supports both VStudio 2003 & VStudio 2005. You can expect the new release candidate quite soon.
Yay! That's great news.
Does that mean that we have fixed http://hackage.haskell.org/trac/ghc/ticket/756?
Cheers, Simon

I would love to see an updated VH. Need a beta tester? ;)
Keep up the great work!
Jason
On 7/27/06, Krasimir Angelov
Yes. It is working well with the new threaded RTS.
On 7/27/06, Simon Marlow
wrote: On 27 July 2006 12:37, Krasimir Angelov wrote:
On 7/27/06, Simon Marlow
wrote: The version of GHC you have with Visual Haskell doesn't have the fixes unfortunately, so you would have to drop VH and use a GHC snapshot or wait until we can put out a new Visual Haskell (no timeframe for that as yet).
Actually I am working on the next Visual Haskell release. It is working with the latest GHC snapshot and supports both VStudio 2003 & VStudio 2005. You can expect the new release candidate quite soon.
Yay! That's great news.
Does that mean that we have fixed http://hackage.haskell.org/trac/ghc/ticket/756?
Cheers, Simon

Hi Jason and Krasimir
On 7/27/06, Krasimir Angelov
I am using the same technique to build VSHaskell itself.
Have you tried using --mk-dll with --make (ie only specifying extra ghc-flag in .cabal)? It should work with current ghc head, but not with the ghc coming with old Visual Haskell. Best regards, --Esa

Hi Esa,
Have you tried to build DLL with Cabal using --mk-dll as you
described? I just tried to use it for Visual Haskell but it doesn't
work. It seems like when there is --make and -o options then GHC is
looking for Main module and complains if there isn't. I remember that
it wasn't working with the old GHC versions but you said that it
should work with the recent GHC-6.6.
Cheers,
Krasimir
On 7/28/06, Esa Ilari Vuokko
Hi Jason and Krasimir
On 7/27/06, Krasimir Angelov
wrote: I am using the same technique to build VSHaskell itself.
Have you tried using --mk-dll with --make (ie only specifying extra ghc-flag in .cabal)? It should work with current ghc head, but not with the ghc coming with old Visual Haskell.
Best regards, --Esa
participants (5)
-
Esa Ilari Vuokko
-
Jason Dagit
-
Krasimir Angelov
-
Simon Marlow
-
Simon Marlow