[Haskell-cafe] Creating DLLs with GHC

SevenThunders mattcbro at earthlink.net
Fri Sep 29 01:20:55 EDT 2006

SevenThunders wrote:
> I am having some difficulty with creating a dynamic link library using 
> GHC on windows XP.

I am having some problems with GHCs stdout when a Haskell program is called
from a windows program.

As I noted earlier I am calling some Haskell code from C as a bridge to
being able to
ultimately call Haskell from Matlab 6.5.

The Haskell code is compiled into a .DLL file on a windows machine.
Matlab calls some C code which then calls the Haskell code.

As soon as it gets into the Haskell code I get this run time error in

<stdout>: hPutChars: invalid argument (Bad File Descriptor)

The Haskell code seems to work correctly if called from a stand-alone C

Matlab does not properly redirect stdout so any printf calls from the C code
simply fail to print.
However Haskell's behavior is to halt after generating a runtime error.

The C code used to generate the Haskell .dll is of course mingw gcc, but the
C code used to create my Matlab mex file is Microsoft VC++ 6.0.  I tried to
redirect stdout using freopen() in C, but that never seems to work with
Microsoft.  At any rate it certainly doesn't effect Haskells use of stdout. 
I think in general for windows programs there is no stdout defined, whereas
it's always defined for console programs.

My question is, is there some way I can redirect stdout from inside Haskell
so that all output is sent to a file?  Is there an equivalent of freopen()
in Haskell that works?
View this message in context: http://www.nabble.com/Creating-DLLs-with-GHC-tf2342692.html#a6559542
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

More information about the Haskell-Cafe mailing list