# SDL: disabling stdout.txt

This topic is 4641 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 <iostream>, 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

##### Share on other sites
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.

##### Share on other sites
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]

##### Share on other sites
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

##### Share on other sites
Isnt this what you are looking for?

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

its in their regular FAQ...

##### Share on other sites
I had success by doing the following for the gcc compiler in DevC++:

- 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

##### Share on other sites
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' 
-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' ]

##### Share on other sites
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.

##### Share on other sites
ninmonkeys, your settings look fine, but you're missing the following from your compiler options:

-Dmain=SDL_main

1. 1
2. 2
3. 3
4. 4
5. 5

• 14
• 9
• 10
• 12
• 17
• ### Forum Statistics

• Total Topics
632909
• Total Posts
3009172
• ### Who's Online (See full list)

There are no registered users currently online

×