在病毒迫使我重置为出厂状态后,我一直试图在我的计算机上设置 SDL。让 SDL 在我的 IDE CodeBlocks 上运行很容易,但设置扩展库就没那么容易了。 CodeBlocks 识别库的存在,但在 SDL_ttf header 和 SDL_image header 中给我多个错误。 给我带来麻烦的代码部分是这样的:
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
第一行生成错误“error: expected unqualified-id before string constant”,第三行生成上述错误和错误“error: expected '}' before end of line”。 我的猜测是,这可能与用 C 编写的 SDL 有关,也许我的 CodeBlocks 尚未配置为识别 C。
编辑:测试源码是这样的:
SDL_Surface* imageBlitingFunctions::loadText(Uint8 red, Uint8 blue, Uint8 green, std::string fontname, int fontSize, std::string text)
{
SDL_Color textColor = {red, blue, green};
TTF_Font *font1 = TTF_OpenFont(fontname.c_str(), fontSize);
SDL_Surface *message1 = TTF_RenderText_Solid(font1, text.c_str(), textColor);
return message1;
}
最佳答案
解决了问题。显然项目文件不知何故被破坏了,所以我只是将脚本转移到另一个项目并且一切正常。
关于c++ - SDL_TTF header 给我带来麻烦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26436193/