[MLton-user] Linking (?) 'print' means I can only run from the mingw command line

Tom 7 twm at andrew.cmu.edu
Sun Sep 14 10:07:33 PDT 2008


Hey,

I'm trying to debug a problem with using mlton+mingw+SDL on windows. 
Everything works fine when I run my app from the mingw command line, but 
when I run it from the DOS prompt or by clicking it in explorer, it 
terminates immediately and silently. I spent some time whittling it down 
and it happens even when I'm not using SDL. I reduced it to the following 
small oddity.

Here's the scenario. With these two lines:

   val mb_ = _import "MessageBoxA" : MLton.Pointer.t * string * string * MLton.Pointer.t -> unit ;
   val () = mb_(MLton.Pointer.null, "Click.\000", "\000", MLton.Pointer.null)

in a file called clicktest.sml compiled with the command line

   mlton @MLton max-heap 512m -- -cc-opt "-I/usr/local/include" -keep g -keep o -verbose 3 -cc-opt "-g -DDEBUG_X86CODEGEN" -link-opt "-L/usr/local/lib -lmingw32 -mwindows" -output clicktest.exe -default-ann 'allowFFI true' clicktest.sml

runs from the mingwin prompt, DOS prompt, and double-clicking in explorer, 
and produces a message box as expected. But these three lines:

   val mb_ = _import "MessageBoxA" : MLton.Pointer.t * string * string * MLton.Pointer.t -> unit ;
   val () = mb_(MLton.Pointer.null, "Click.\000", "\000", MLton.Pointer.null)
   fun g s = print s

produces a program that runs from the mingw prompt as before, but when run 
from DOS or by double-clicking, does nothing. (By adding debugging output 
as messageboxes in x86-main.h I'm able to see that it gets as far as the 
call to MLton_jumpToSML, but I don't know what happens then.) The only 
difference is the mention of the 'print' function in dead code. My guess 
is that this causes some I/O part of the Basis to be included (But then 
not eliminated?), which creates some more initialization steps (binding to 
stdout, perhaps) that abort the program when run in the click environment 
rather than the mingw command line environment.

Does this sound plausible? If so, what code should I look at? Or is there 
some simple fix? =)

BTW, I'm doing this development on Vista, but I get the same behavior on 
XP (though I have not delved as deep there).

  - Tom

[ NEW! : http://tom7.org/       ]
[ OLD! : http://fonts.tom7.com/ ]




More information about the MLton-user mailing list