SDL은 프로그램 진입 점을 자신의 진입 점으로 대체합니다.
자세한 내용은 here, there 및 over there입니다.
기본적으로 표준 출력 (stdout, stdin and stderr)은 파일로 리디렉션됩니다.이 파일은 보유한 스트림의 내용과 동일한 이름을가집니다.
프로그램의 디렉토리에 있어야합니다.
1 - 당신은 SDL_Init 다음 후 를 삽입해야하는 동작을 생략하려면 스트림
을 Redireting. 나중에 추가 기능이 작동하지 않는 경우 기본 상단에 추가하십시오.
freopen ("CON", "w", stdout);
freopen ("CON", "r", stdin);
freopen ("CON", "w", stderr);
이 여전히 시도 작동하지 않으면.
// Start : edit
SDL_Init (...)
FILE * ctt = fopen("CON", "w"); // c
// or
ofstream ctt("CON"); // c++
// End : edit
freopen ("CON", "w", stdout);
freopen ("CON", "r", stdin);
freopen ("CON", "w", stderr);
/* ... */
// Start : edit
fclose (ctt); // c
// or
ctt.close(); // c++
// End : edit
는 CON here에 대해 알아보십시오.
"CON"이 NULL로 대체 될 수있는 것으로 보았습니다. (그것은 가치가 무엇인지에 대한 .)
freopen(NULL,"w",stdout);
freopen(NULL,"w",stdout);
freopen(NULL,"w",stderr);
freopen을 방법의 다른 변형. CONOUT $ 및 CONIN $ here 약
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
더.
이전 및 GNU/Linux BSD, Solaris, Mac OS 등을 사용하는 데 문제가있는 경우 다음을 시도하십시오.
freopen ("/dev/tty", "w", stdout);
freopen ("/dev/tty", "r", stdin);
freopen ("/dev/tty", "w", stderr);
이 방법을 적용하면 아래의 코드로 보일 것입니다.
/* ... */
int main {
SDL_Init(SDL_INIT_VIDEO);
/* start : redirecting the streams to the console */
FILE * ctt = fopen("CON", "w"); // Edit
freopen ("CON", "w", stdout);
freopen ("CON", "r", stdin);
freopen ("CON", "w", stderr);
/* end : redirecting the streams to the console */
/*start : your code */
putenv("SDL_VIDEO_CENTERED=center");
SDL_WM_SetCaption("Railroad Builder",NULL);
SDL_WM_SetIcon(IMG_Load(strcat_const(parentFolder(exePath),
"/icon.png")),NULL);
SDL_SetVideoMode(MAIN_WINDOW_WIDTH,MAIN_WINDOW_HEIGHT,32,
SDL_OPENGL);
int running = 1;
while(running){
printf("myVar = %d",myVar);
}
/* end : your code */
/* ... */
fclose (ctt); // Edit
/* ... */
}
예 : SDL faq에서 찾을 수 있습니다.
2 - 프로그램의 진입 점 변경
또한 UNDEFINE SDL의 주요 그래서 메인 호출 할 첫 번째가 될 것입니다 수 있습니다.
이렇게하려면 주 기능 앞에 다음 지침을 추가하십시오.
/*...*/
#ifdef main
#undef main // Prevent SDL from overriding the program's entry point.
#endif
/***/
int main(int argc, char **argv){
/*...*/
}
또는
/*...*/
#ifdef __MINGW32__ // It can be __MINGW64__. Chose according to your architecture.
#undef main // Prevent SDL from overriding the program's entry point.
#endif
//or
#if defined(__MINGW32__) || defined(__MINGW64__)
#undef main // Prevent SDL from overriding the program's entry point.
#endif
/*...*/
int main(int argc, char **argv){
/*...*/
}
소개
MINGW32 and MINGW64
3 - 당신은 표준 출력/표준 에러를 방지 할 수있는 SDL 사이트에서 다운로드 미리 컴파일 된 SDLmain.dll 바이너리로 SDL
재 구축 텍스트 파일로 리디렉션되지 않습니다. 당신이 할 수있는 일은 NO_STDIO_REDIRECT 컴파일러 플래그로 SDLmain을 직접 컴파일하거나 아니면 SDLmain을 전혀 사용하지 않는 것입니다.
SDLmain을 사용하지 않으면 이식성이 깨질 수 있으므로 권장하지 않습니다.
가끔 stdout.txt와 stderr.txt를 실행 파일이있는 디렉토리에 작성하는 것이 좋을 때가 있습니다.
당신은 약간의 속임수로이 작업을 수행 할 수 있습니다 sdl_winmain.h 자신의 프로젝트 디렉토리에 있으며 SDL 소스 패키지에서 SRC/메인/SDL_win32_main.c의 재 사본입니다
#include "SDL/SDL.h"
#ifdef WIN32
#include "sdl_winmain.h"
#else
#include "SDL/SDL_main.h"
#endif
. 이렇게하면 다른 플랫폼에서도 여전히 이식성이 있지만 Windows의 stdout/stderr 파일을 가져올 수 없습니다.
이것은 SDL faq의 것입니다. 더 많은 정보를 얻으려면 wiki을 얻으십시오. 소스 소스 코드에서
에서
3.5 (~/SDL2-2.0.4// SDL_main.h 포함) 나는 다음과 같은
#ifndef SDL_MAIN_HANDLED
#if defined(__WIN32__)
/* On Windows SDL provides WinMain(), which parses the command line and passes
the arguments to your main function.
If you provide your own WinMain(), you may define SDL_MAIN_HANDLED
*/
의 온라인 사본을 발견했습니다 source code.
NO_STDIO_REDIRECT 정의에 성공하지 못하면 SDL_MAIN_HANDLED를 시도하십시오. SDL-1.2.15에서 발견에
은 아무데도 없었다 (~/SDL-1.2.15/포함/SDL은/SDL_main.h)하지만, 내가 무엇을 발견 했는가하는 것은 따라야하는 것
#define main SDL_main
입니다 위의 #undef main 메소드를 사용하십시오.
4-
대신 표준 출력의 stderr로 오류 메시지를 보내 흥미로운 일이 될 수도 있습니다. 그렇게하려면 perror 또는 fprintf을 사용해보세요.그래서 같이
는 :
/*...*/
perror ("Error"); // the string cannot be formatted
fprintf (stderr,"Error %s", str_err_msg); // the string can be formatted
/*...*/
당신은 우리에게 당신이 사용하고있는 코드를 보여줄 수 있을까요? – byxor
@BrandonIbbotson 여기 있습니다. –
[SDL 콘솔 출력은 디버깅 할 때 작동하지만 EXE로 실행하면 작동하지 않습니다] (http://stackoverflow.com/questions/14593783/sdl-console-output-works-when-debuging-but-not-when) -run-with-the-exe) –