From: Paul G. <pga...@at...> - 2003-05-22 03:22:03
|
> Hello > > If I build a Win32 app with flag -mwindows, I wonder if there is a way > to enable console output from printf, to the console(sh) that I start > the program(started from commandline in msys sh)? Yes. It is a fairly straightforward operation using C/C++: $ g++ -v Reading specs from d:/msys/1.0/mingw/bin/../lib/gcc-lib/mingw32/3.2.3/specs Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 -- prefix=/mingw --enable-threads --disable-nls --enable-languages=c++,f77,objc --disable-win32-registry --disable- shared --enable-sjlj-exceptions Thread model: win32 gcc version 3.2.3 (mingw special 20030504-1) Source follows: #include <windows.h> #include <iostream> int WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) { MessageBox (NULL, "Hello, Windows!", "Hello", MB_OK); printf("hello world\n"); return 0; } end of source compile with: g++ hello.cpp -ohello.exe -mwindows -mconsole Automatic output to both a window (message box) and to the Msys sh/console. Allows you to immediately output to the console (under Msys shell) and can be extended to include a full-blown Window as needed. What is critical is that the -mconsole switch is included when the app is compiled (in addition to the -mwindows switch). For C++ std::cout << "Hellowin for C++"; works as well for console output in the above source code example, even though it will generate some warnings. The above example will not work after "msysdvlpr" is invoked due to differences between compiler being used for Msys development and the compiler being used for Mingw development. Msysdvlpr sets the following as the default compiler on this system: $ g++ -v Reading specs from /bin/../lib/gcc-lib/i686-pc-msys/2.95.3-1/specs gcc version 2.95.3-1 and results in the following: $ g++ hello.cpp -ohello.exe -mwindows -mconsole In file included from /usr/include/g++-3/streambuf.h:36, from /usr/include/g++-3/iostream.h:31, from /usr/include/g++-3/iostream:6, from hello.cpp:2: /usr/include/g++-3/libio.h:30: _G_config.h: No such file or directory Paul G. > > psksvp > > > > ------------------------------------------------------- > This SF.net email is sponsored by: ObjectStore. > If flattening out C++ or Java code to make your application fit in a > relational database is painful, don't do it! Check out ObjectStore. > Now part of Progress Software. http://www.objectstore.net/sourceforge > _______________________________________________ MinGW-users mailing > list Min...@li... > > You may change your MinGW Account Options or unsubscribe at: > https://lists.sourceforge.net/lists/listinfo/mingw-users |