gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:42:11 26 4
gpt4 key购买 nike

我正在尝试使用 VS2012(2010 也可用)在 Windows 中构建一个项目,其中包括依赖于 FreeType 的 FTGL。

当我尝试构建我的项目时,我看到大量以下 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 库目录并将它们添加到 项目设置 -> 链接器 -> 附加依赖项 这样我就有了以下行:

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

不要认为这很重要,因为我没有任何 Unresolved 依赖项,但我的项目中有以下内容 -> C/C++ -> Additional Include Dirs

$(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)。

谁能帮我解决这些错误?

最佳答案

确保您的库是使用 code generation 下的相同 runtime library 选项生成的

  • /MD 和/MDd 用于多线程(调试)
  • /MT 和/MTd 用于多线程 DLL(调试)

所有相互依赖的项目都应该有相同的选项。


此外,如果导入使用/MD 和/MDd 构建的静态库,您可能会遇到 LIBCMT 冲突。将 LIBCMT 添加到 ignore libraries for linker 可以避免这个问题。

关于c++ - Windows 中使用 Visual Studio 的链接器错误 (LNK2005),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20940625/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com