SDL_TTF标头给我带来麻烦

SDL_TTF header giving me trouble

本文关键字:麻烦 TTF SDL      更新时间:2023-10-16

在病毒迫使我重置为出厂状态后,我一直在尝试在我的计算机上设置SDL。用我的IDE CodeBlocks运行SDL很容易,但设置扩展库就不那么容易了。CodeBlocks可以识别库的存在,但在SDL_ttf标头和SDL_image标头中会出现多个错误。代码中给我带来麻烦的部分是:

/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif

第一行生成错误"error:字符串常量前应为非限定id",第三行生成上述错误和错误"error:行尾前应为'}'"。我的猜测是,这可能与SDL是用C编写有关,也许我的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;
}

解决了这个问题。显然,项目文件不知怎么被破坏了,所以我只是把脚本转移到另一个项目,一切都很好。