问题描述
我正在使用C ++和SDL2在Windows 7下使用Code :: Blocks 12.11开发一个小游戏.我正在使用mingw32-gcc编译器,并下载了SDL2的标准预编译Windows发行版(现在是2.0.1),并使用了i686-w64-mingw32版本.到目前为止,一切正常,我正在获取图形输出,并且SDL_ttf扩展也有效.
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.
从一开始就没做过的唯一事情就是按照预期从SDL将我的stdout放入txt文件中:
The only thing that has never worked from the beginning is getting my stdout in a txt file from SDL as intended:
-
不管我做什么,我永远都不会在任何地方获得stdout.txt或stderr.txt,甚至从未见过创建过的那些文件.
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.
当我将程序编译为控制台应用程序时,在该控制台中收到SDL错误输出,但根本没有cout或printf或fprintf(stdout ...)(尝试了全部三个).
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).
在不使用SDL进行编程的情况下,控制台stdout输出可以正常工作.
When programming something without SDL the console stdout output works fine.
因此,问题不在于将stdout重新路由到控制台,这是有关SDL和stdout的常见问题,问题是我什至没有将输出按预期写入相应文件中.
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.
在预编译和未更改的SDL 2.0.0和SDL 2.0.1中都会发生这种情况.
This happens both with SDL 2.0.0 and SDL 2.0.1, both precompiled and unaltered.
这是我的主要功能的样子. myGame.GameStart()会运行包括清理在内的所有内容.我是C ++的新手,所以这里也可能会出现一些奇怪的错误.
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;
}
我正在使用-g和-std = c ++ 0x进行编译.
I'm compiling with -g and -std=c++0x.
我正在链接mingw32,SDL2main,SDL2,SDL2_ttf(按此顺序)和mwindows.
I'm linking mingw32, SDL2main, SDL2, SDL2_ttf (in that order) and mwindows.
要查看我作为控制台应用程序编译的控制台,并在执行结束时使用选项Pause.
To see the console I compile as console application and use the option Pause when execution ends.
我对Code :: Blocks还是很陌生,我还没有深入研究编译器和调试器的各种选项.
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?
推荐答案
解决(非常简单):
SDL 1.2可以输出到文件中,而SDL 2则不可以.但是,由于SDL 2是新的,网上的大多数信息(旅游景点等)都是关于SDL 1.2的.
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.
此外,使用-mwindows进行编译会将所有stdout和stderr都发送为null.
Furthermore compiling with -mwindows sends all stdout and stderr to null.
不进行编译就解决了我的问题.
Compiling without solves my problem.
这篇关于不含SDL的stdout.txt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!