I'm working on a little game using C++ with SDL2 using Code::Blocks 12.11 under Windows 7. I'm using the mingw32-gcc compiler and downloaded the standard precompiled Windows distribution of SDL2 (2.0.1 now) and use the i686-w64-mingw32 version. So far stuff is working, I'm getting graphical output and the SDL_ttf extension works too.
The only thing that has never worked from the beginning is getting my stdout in a txt file from SDL as intended:
Regardless of what I do, I NEVER get stdout.txt or stderr.txt anywhere, haven't seen those files created even once.
The files also aren't created during runtime and deleted when the program is closed, they never are created at all.
When I compile my program as a Console application I get SDL error output in that console but no cout or printf or fprintf(stdout...) at all (tried all three).
When programming something without SDL the console stdout output works fine.
So the problem is not to reroute stdout to console which is the usual question about SDL and stdout, the problem is that I'm not even getting my output written into the according files as intended.
This happens both with SDL 2.0.0 and SDL 2.0.1, both precompiled and unaltered.
This is how my main function looks like. myGame.GameStart() runs everything including cleaning up. I'm fairly new to C++, so there might be some weird error here as well.
#include "SDL.h"
#include "SDL_ttf.h"
int main(int argc, char* argv[]) {
TTF_Init();
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER|SDL_INIT_EVENTS);
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN);
MyGameClass myGame;
myGame.GameStart();
SDL_Quit();
TTF_Quit();
return 0;
}
I'm compiling with -g and -std=c++0x.
I'm linking mingw32, SDL2main, SDL2, SDL2_ttf (in that order) and mwindows.
To see the console I compile as console application and use the option Pause when execution ends.
I'm fairly new to Code::Blocks and I haven't dived deeper into the various options for compiler and debugger.
Has anyone an idea? Am I linking in the wrong order? Linking the wrong stuff? Is my main function wrong?
Solved (embarrassingly simple):
SDL 1.2 did that outputting into files, SDL 2 does not. However most information (toturials and such) on the net is about SDL 1.2 since SDL 2 is new.
Furthermore compiling with -mwindows sends all stdout and stderr to null.
Compiling without solves my problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With