I’m creating a project with SDL and I have realized that output does not
work in the console, instead everything is written to the output file
stdout.txt.
I have heard that creating GUI windows application causes any function
that write to stdout, stderr are redirected into the GUI application but
the problem is that my project is not a GUI application.
By the way I need to link against SDLmain if not it will complains about
lacks of WinMain at 16 which is my main problem. How do I prevent to link
agains SDLmain since I want a simple console application that uses SDL ?
This is my sample code and my CMakeLists.txt :
cmake_minimum_required(VERSION 2.8)
project(cmaketest C)
I don’t use CMake so I cannot help you with that part specifically.
If you were using Visual Studio, you would set the “subsystem” of your
project to console. You can continue to link to SDLmain, it provides a
console entry point too.
You can either re-redirect (or un-redirect) stdout and stderr, or
recompile SDLmain.lib with NO_STDIO_REDIRECT defined. See http://forums.libsdl.org/viewtopic.php?t=7517 for a similar request
recently.
Alternatively, you can look at the Windows SDL_win32_main.c to see
what SDL is doing for you, and you can replicate as much (or all) of
that as you need in your own application. SDL_win32_main.c is in the
public domain, so you are free to copy/modify it without licensing
issues.
Regards,
– BrianOn 9 September 2011 12:38, David Demelier <demelier.david at gmail.com> wrote:
Hello,
I’m creating a project with SDL and I have realized that output does not
work in the console, instead everything is written to the output file
stdout.txt.
I have heard that creating GUI windows application causes any function that
write to stdout, stderr are redirected into the GUI application but the
problem is that my project is not a GUI application.
By the way I need to link against SDLmain if not it will complains about
lacks of WinMain at 16 which is my main problem. How do I prevent to link
agains SDLmain since I want a simple console application that uses SDL ?
Thanks the set_target_properties remove the need of SDLmain but the
stdout is still outside in a file, I will recompile SDL using
NO_STDIO_REDIRECT. Thanks
Thanks the set_target_properties remove the need of SDLmain but the
stdout is still outside in a file, I will recompile SDL using
NO_STDIO_REDIRECT. Thanks
Maybe the attached patch is useful…so it won’t redirect stdio if we’ve
actually got a console to write it to. I’m not sure if I should apply
this, though.
It sounds like something people would certainly like. Lots of people
want to reconnect the console, certainly while developing their
program.
However, it could break people who currently rely on stdout.txt for
logging. It could be protected by a macro (not unlike SDL_NO_REDIRECT)
for the moment?
– BrianOn 11 September 2011 02:36, Ryan C. Gordon wrote:
Thanks the set_target_properties remove the need of SDLmain but the
stdout is still outside in a file, I will recompile SDL using
NO_STDIO_REDIRECT. Thanks
Maybe the attached patch is useful…so it won’t redirect stdio if we’ve
actually got a console to write it to. I’m not sure if I should apply this,
though.