簡體   English   中英

Windows中使用Visual Studio的鏈接器錯誤(LNK2005)

[英]Linker errors (LNK2005) in Windows using Visual Studio

我正在嘗試使用包含FTGL(取決於FreeType)的VS2012(也提供2010)在Windows中構建項目。

當我嘗試構建項目時,我看到大量以下LNK2005錯誤:

Error 204 error LNK2005: "private: __thiscall FTFont::FTFont(class FTFontImpl *)" (??0FTFont@@AAE@PAVFTFontImpl@@@Z) already defined in FTFont.obj  buildDir\ftgl.lib(ftgl.dll)
Error 238 error LNK2005: "private: __thiscall FTGlyph::FTGlyph(class FTGlyphImpl *)" (??0FTGlyph@@AAE@PAVFTGlyphImpl@@@Z) already defined in FTGlyph.obj    buildDir\ftgl.lib(ftgl.dll)
Error 249 error LNK2005: "private: __thiscall FTLayout::FTLayout(class FTLayoutImpl *)" (??0FTLayout@@AAE@PAVFTLayoutImpl@@@Z) already defined in FTLayout.obj  buildDir\ftgl.lib(ftgl.dll)
Error 213 error LNK2005: "protected: __thiscall FTFont::FTFont(char const *)" (??0FTFont@@IAE@PBD@Z) already defined in FTFont.obj  buildDir\ftgl.lib(ftgl.dll)

我使用他們提供的msvc-> vc8解決方案(升級到vs2010)構建了FTGL庫。 這為調試和發布創建了以下文件:

ftgl_static.lib
ftgl.lib
ftgl.dll

將這些庫放到我的vc lib目錄中,並將它們添加到“ 項目設置”->“鏈接器”->“其他依賴項”,這樣我就有了以下幾行:

ftgl.lib
glui32.lib
glut32.lib
glu32.lib
opengl32.lib
freetype.lib
%(AdditionalDependencies)

沒關系,因為我沒有任何未解決的依賴關系,但是我的項目中有以下內容-> C / C ++->其他包含目錄

$(SolutionDir)..\..\code\lib\freetype2\include\freetype2\config
$(SolutionDir)..\..\code\lib\freetype2\include\freetype2
$(SolutionDir)..\..\code\source
$(SolutionDir)
$(SolutionDir)..\..\code\lib\FTLayout
$(SolutionDir)..\..\code\lib\FTGlyph
$(SolutionDir)..\..\code\lib\FTGL
$(SolutionDir)..\..\code\lib\FTFont
$(SolutionDir)..\..\code\lib
$(SolutionDir)..\..\code\headers
%(AdditionalIncludeDirectories)

嘗試玩忽略依賴性,但沒有得到任何幫助。 我還在這里和其他站點上嘗試了各種解決方案,包括:

在出現此問題之前,我已經看到此gamedev 主題上描述的LNK2019錯誤。 通過將lib添加到項目中的其他依賴項可以解決此問題,但是引入了LNK2005錯誤。

如果有幫助,則該項目將構建在OS X中; 但是,對於Windows,這些庫有所不同(OS X中的dylib與Win中的lib / dll)。

誰能幫助我解決這些錯誤?

確保在code generation下使用相同的runtime library選項生成了lib

  • / MD和/ MDd用於多線程(調試)
  • / MT和/ MTd用於多線程DLL(調試)

相互依賴的所有項目都應具有相同的選項。


另外,如果導入使用/ MD和/ MDd構建的靜態庫,則可能會發生LIBCMT沖突。 將LIBCMT添加到鏈接ignore librariesignore libraries中可以避免此問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM