![](/img/trans.png)
[英]std::map linker error ndk r8c with APP_STL := gnustl_static
[英]Linker Error with use of stl map
我收到以下鏈接器錯誤:
錯誤1錯誤LNK2001:無法解析的外部符號“私有:靜態類std :: map,類std :: allocator>,struct SDL_Surface *,struct std :: less,class std :: allocator>>,class std :: allocator,class std :: allocator> const,struct SDL_Surface *>>> CSurface :: loadedSurfaces“(?loadedSurfaces @ CSurface @@ 0V?$ map @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ PAUSDL_Surface @@ U?$ less @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@ 2 @ V?$ allocator @ U?$ pair @ $$ CBV?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ PAUSDL_Surface @@@ std @@@ 2 @@ std @ @A)CSurface.obj
CSurface編譯單元的頭文件和cpp文件的代碼位於:
是什么導致此鏈接器錯誤發生:(它使我發瘋。
您已經聲明了loadedSurfaces
但是尚未定義它。 您需要將以下內容恰好添加到一個轉換單元中,以實際聲明該變量:
map<string, SDL_Surface*> CSurface::loadedSurfaces;
現在,類定義中的loadedSurfaces
就像該函數的原型一樣。 當您嘗試使用它時,鏈接器會繼續查找它,因為它看到了前向聲明,但從未在任何地方找到實際的定義。 您必須給它一個定義,並且鏈接器會滿足,因為它知道每個人在使用loadedSurfaces
名稱時都在談論的實際翻譯單元中的實際變量。
CSurface::loadedSurfaces
已聲明但未定義。 將以下內容添加到.cpp
文件中:
map<string, SDL_Surface*> CSurface::loadedSurfaces;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.