Using the -mwindows
switch with an application that uses Ada.Text_IO seemingly causes the application to either exit / exception out. I was wondering if anyone knew of another switch that I could pair with this to allow the program to run. The text_io stuff is just for debug, so I only specify the -mwindows
switch in release mode, but I do want it to spawn the console and print stuff in debug mode.
The switch is used for GUI applications. If you want a console application then you need to omit the switch.
A GUI process is normally spawned without standard files. The Ada.Text_IO error comes from there. You can start a GUI application manually in a way that it would have the standard output/error passed to the process. For example under a console:
> my_program.exe > output.txt >2&1
GPS catches the output and error you start a GUI application from under it.
Then for debug purpose it is best to use tracing into an external file. Otherwise use a MessageBox (Win32 API). In GtkAda you can use:
procedure Say
( Message : UTF8_String;
Title : UTF8_String := "";
Mode : UTF8_String := Stock_Dialog_Info;
Justification : Gtk_Justification := Justify_Left;
Parent : access Gtk_Widget_Record'Class := null
);
Thanks, I’m aware of this. I wanted to do it as a console application when not compiled for “release” (some things happen before the GUI starts, and I would like to see debug on them) but also spawn it as only a GUI application when compiled for “release”.
I was hoping to avoid having to do a log file if possible, so I was wondering if there were any switches to tell GNAT the intention there.
Simply remove -mwindows in the debug build. That will open a console upon application start.
Yep, that’s what I’m doing, the problem is the debug statements cause the application to crash when in “release” mode with -mwindows
specified, so I think GNAT doesn’t handle it well with that switch if one does use Ada.Text_IO for debugging.
I was hoping the Put_Line’s and such would just silently get eaten when -mwindows is specified, but they cause exceptions instead.
Don’t you see an irony here?
GNAT has nothing to do with any of that. This is a Windows behaviour per design. It is not even MSYS, if you linked it using MS-linker you would get exactly same behaviour.
You can use VSS.Text_Streams.Standards.Output_Stream
instead, it outputs to stdout
when it is available and do nothing otherwise.
Thanks. That’s kind of the way I am currently going. I can’t get VSS, but I’m emulating the same thing using pragma Debug and wrapping that in a function for now.
Just to reiterate: