Author Topic: No output for printf statements in console window  (Read 22806 times)

Offline gagabla

  • Single posting newcomer
  • *
  • Posts: 3
No output for printf statements in console window
« on: April 14, 2009, 04:09:26 pm »
Hi,
running my program in C::B (by clicking on the "Run" button) i don't see any output in the console window except for the "Process returned 0 (0x0) execution time: ... Press any key to continue" message.
Running the executable manually in msys/MinGW shell i see all the output. Running it manually in the Windows shell, i see nothing. So i think there are two solutions: either running it inside C::B via the mingw shell, or somehow configure it, so that printf-messages are visible in the windows shell. The later one is my favorite.

When i create a new Project inside Codeblocks with the default hello-World example, every thing works fine.

The project is pretty big, so i can't post runnable source-code here, any ideas what the problem could be?

best regards
Janosch
« Last Edit: April 14, 2009, 04:11:16 pm by gagabla »

Offline gagabla

  • Single posting newcomer
  • *
  • Posts: 3
Re: No output for printf statements in console window
« Reply #1 on: April 15, 2009, 01:20:37 pm »
Perhaps its important to notice, that the application is using OpenGL, and that the graphics are drawn into a window that is opened with the CreateWindow command.
This part of the application is not written by me, so i dont have deeper insight in the whole process of initializing a window and then drawing into it. Could it be, that my code (rendering code, mostly) runs in a different "context" somehow, not in the "console context"?
BR janosch
« Last Edit: April 15, 2009, 01:25:45 pm by gagabla »

Offline jarro_2783

  • Multiple posting newcomer
  • *
  • Posts: 99
    • Project Freedom
Re: No output for printf statements in console window
« Reply #2 on: April 16, 2009, 02:08:22 am »
I think this happens in windows when you use WinMain and make it a windows gui program instead of a console program (compiled with -mwindows I think). As far as I know windows completely discards console output when you do this. I'm guessing msys does something different and you still see the output.
The best way to fix it would be to use main as your main function instead of WinMain and not compile with -mwindows.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: No output for printf statements in console window
« Reply #3 on: April 16, 2009, 12:13:22 pm »
I think this happens in windows when you use WinMain and make it a windows gui program instead of a console program (compiled with -mwindows I think). As far as I know windows completely discards console output when you do this. I'm guessing msys does something different and you still see the output.
The best way to fix it would be to use main as your main function instead of WinMain and not compile with -mwindows.

I agree with this guess. :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline gagabla

  • Single posting newcomer
  • *
  • Posts: 3
Re: No output for printf statements in console window
« Reply #4 on: April 16, 2009, 08:18:55 pm »
Hi,
thanks for your answers. I removed the -mwindows option from the linker options, but first got a lot of errors for some 'windowish' functions like "CreateSolidBrush" for instance.
I then added the libraries gdi32, comdlg32 and user32 to the link libraries (found this hint on http://gcc.gnu.org/ml/gcc-help/2004-01/msg00225.html) and it worked.

Thanks a lot, i know that printf is not the best way to debug ;) but i like to see somehow what happens in my application sometimes :)