Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL: disabling stdout.txt

Started by ninmonkeys Jan 25, 2006 at 11:50 PM 7 replies 10.4k views
Original Post
ninmonkeys
ninmonkeys
Is it possible to disable the creation of stdout.txt and stderr.txt without having to rebuild the SDL source? I'm not currently including , or using std::cout, or std::cerr. (Not outputting to stdout, or stderr in any way) I checked both the VC6, and ming development zips for the library mentioned in: http://www.libsdl.org/faq.php?action=listentries&category=4#85 but I don't find it. (Must be too old of an answer?) I was hoping I don't have to recompile SDL if I don't have to, but I will try if I have to. (I had tried in the past, but I had problems on win32) -- thanks, monkey
ShoeStringGames
ShoeStringGames
Dont take my word on it 100% but I asked this question a whiles back. I was told that you cant disable them normally, so if you wanted to edit the SDL code, go for it.
--brb
Drew_Benton
Drew_Benton
Quote:
Original post by ninmonkeys
(I had tried in the past, but I had problems on win32)


I'm thinking along the same things as ShoeStringGames, but if you have Visual Studio, recompiling is a piece of cake, you just select the NO_STDIO configuration and build that. If you use Dev-Cpp, then you will have to set one preprocessor definition to disable the stdio, but that should be it. If you run into troubles, I'm sure we can help you [smile]
Xeee
Xeee
well, I needed to do this a while ago and I couldn't, so I did a simple hack(which was mentioned on SDL users mailing list I think). which is redirecting the output to somewhere else. but this doesn't solve the problem entirely.
to be clear, here is the sequence:
1- SDL gets initialized and creates stdout.txt
2- you use platform-specific functions to redirect stdout to anything(you can redirect it to NUL to throw it away).
3- anything written to stdout while the program is running will get redirected.
4- when SDL gets deinitialized it finds that stdout.txt is empty so it deletes it.

I can give you the code to do this but I'm not home now, if this solution suits you, tell me and I'll send you the code when I'm home.

Diaa Sami
xee..
Twixly
Twixly
Isnt this what you are looking for?

http://www.libsdl.org/cgi/docwiki.cgi/FAQ_20Console

its in their regular FAQ...
Windows - Dev-Cpp 4.9.9 - SDL - SDL_Net
MatrixCubed
MatrixCubed
I had success by doing the following for the gcc compiler in DevC++:

- ensure -mwindows is not added as linker option in project
- ensure -lsdlmain is not added as linker option in project
- add SDL_win32_main.c to the project
- make the following change to the source file:

/* The standard output files */#define STDOUT_FILE	TEXT("stdout.txt")#define STDERR_FILE	TEXT("stderr.txt")// *** ADD THIS TEXT BEFORE THE #ifndef BELOW ***#define NO_STDIO_REDIRECT#ifndef NO_STDIO_REDIRECT  #ifdef _WIN32_WCE    static wchar_t stdoutPath[MAX_PATH];    static wchar_t stderrPath[MAX_PATH];  #else    static char stdoutPath[MAX_PATH];    static char stderrPath[MAX_PATH];  #endif#endif


Then you can use regular stdout output:
printf("Text\n");fprintf(stdout, "Text\n");cout << "Text" << endl; // haven't tried this, but it should work
ninmonkeys
ninmonkeys
To clarify, I'm trying to prevent the files from being created at all, since this program is supposed to run on a CD, so it will not have write access to its working directory. ( It sounds like the include the source file will do that, but I haven't been able to get it working so far. )

Twixly: Thanks for the link, I didn't realize there was a more up to date faq.

I think i'm doing this right:
-I am not linking with the flag: -mwindows
-I am not linking wint the flag: -lSDLmain
-I placed the source at c:\programs\sdl_source, and include SDL_win32_main.c: #include "C:\Programs\SDL_source\SDL-1.2.9\src\main\win32\SDL_win32_main.c"

1) I get an error when trying to compile:
[Linker error] undefined reference to `SDL_main' 
My linker flags:
-lmingw32 -lSDL -lSDL_ttf
And i've tried this under both compiler, and c++ compiler
-DNO_STDIO_REDIRECT


2)If this doesn't work, what do I do to compile the source? I have "make" which is in dev-cpp/bin, but there is no "configure" binary.

MatrixCubed: Do I make that change in my source, or in SDL_win32_main.c? I tried both, and both ways i'm getting the same linker error:
  [Linker error] undefined reference to `SDL_main' ]
rip-off
rip-off
i heard on the SDL mailing list that if SDL cant write to its directory it just wont, and all your cout or printf data will just be lost.
MatrixCubed
MatrixCubed
ninmonkeys, your settings look fine, but you're missing the following from your compiler options:

-Dmain=SDL_main

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.