2

我正在使用 Microsoft Visual Studio C++ 2010 Express Edition,并且正在尝试使用 SDL_ttf.lib 编译 SDL 项目并收到以下错误消息:

1>SDL.obj : error LNK2019: unresolved external symbol _TTF_CloseFont referenced in function "void __cdecl DrawTextW(struct SDL_Surface *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,int,int,int,int,int,int,int,int)" (?DrawTextW@@YAXPAUSDL_Surface@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHHHHHHHH@Z)

1>SDL.obj : error LNK2019: unresolved external symbol _TTF_RenderText_Shaded referenced in function "void __cdecl DrawTextW(struct SDL_Surface *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,int,int,int,int,int,int,int,int)" (?DrawTextW@@YAXPAUSDL_Surface@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHHHHHHHH@Z)

1>SDL.obj : error LNK2019: unresolved external symbol _TTF_OpenFont referenced in function "void __cdecl DrawTextW(struct SDL_Surface *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,int,int,int,int,int,int,int,int)" (?DrawTextW@@YAXPAUSDL_Surface@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHHHHHHHH@Z)

1>SDL.obj : error LNK2019: unresolved external symbol _TTF_Init referenced in function "bool __cdecl Init(void)" (?Init@@YA_NXZ)

1>SDL.obj : error LNK2019: unresolved external symbol _TTF_Quit referenced in function _SDL_main

我已经搜索了解决方案,但没有找到任何可以解决我的问题的方法。我没有忘记链接 SDL_ttf.lib,我也将文件夹与它链接,包含标题并将 SDL_ttf.dll 放入我的项目文件夹中。

PS 我对 SDL_image 有同样的问题。

4

2 回答 2

1

通常,该错误来自未按此处所述定义的外部对象。

像这样

// LNK2019b.cpp
// LNK2019 expected
struct C {
   static int s;
};

// Uncomment the following line to resolve.
// int C::s;

int main() {
   C c;
   C::s = 1;
}

您可能需要定义 _TTF 对象的实际实例,例如 SDL::_TTF_XXX

于 2012-06-07T20:23:34.403 回答
1

我以前遇到过这样的错误:

错误 LNK2019:无法解析的外部符号 _TTF_Quit
错误 LNK2019:无法解析的外部符号 _SDL_Init
错误 LNK2019:无法解析的外部符号 _TTF_Init

因为我的项目属性Project|Properties|Configuration Properties|Linker|Input|Additional Dependencies丢失:“SDL.lib SDLmain.lib SDL_ttf.lib SDL_image.lib”

于 2014-02-20T14:34:59.987 回答