Windows中使用Visual Studio的链接器错误(LNK2005)

时间:2014-01-05 23:32:06

标签: c++ visual-studio dll linker linker-errors

我正在尝试使用包含FTGL的VS2012(2010也可用)在Windows中构建一个项目,这取决于FreeType。

当我尝试构建项目时,我看到了大量以下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 lib。这为调试和发布创建了以下文件:

ftgl_static.lib
ftgl.lib
ftgl.dll

将lib放入我的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)

尝试忽略依赖关系,但没有得到任何关键。我还在这里和其他网站上尝试了各种解决方案,包括:

在此问题出现之前,我看到this gamedev topic上描述的LNK2019错误。这是通过将lib添加到项目中的其他依赖项来解决的,但是引入了LNK2005错误。

如果有帮助,该项目将在OS X中构建;但是,Windows的库有些不同(OS X中的dylib与Win中的lib / dll)。

有人可以帮我解决这些错误吗?

1 个答案:

答案 0 :(得分:1)

确保在runtime library

下使用相同的code generation选项生成lib
  • / MD和/ MDd用于多线程(调试)
  • / MT和/ MTd用于多线程DLL(调试)

所有彼此依赖的项目应该具有相同的选项。


此外,如果导入使用/ MD和/ MDd构建的静态库,则可能存在LIBCMT冲突。将LIBCMT添加到ignore libraries以便链接器可以避免此问题。