1

I'm trying to build a project in Windows using VS2012 (2010 also available) that includes FTGL, which depends on FreeType.

When I try to build my project, I see a large number of the following LNK2005 errors:

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)

I built the FTGL lib using their provided msvc->vc8 solution (upgraded to vs2010). This created the following files for both debug and release:

ftgl_static.lib
ftgl.lib
ftgl.dll

Placed the libs into my vc lib directory and added them to the Project Settings -> Linker -> Additional Dependencies so that I have the following line:

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

Don't think it matters since I don't have any unresolved dependencies, but I have the following in my project -> 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)

Tried playing with ignoring dependencies but didn't get anywhere with that. I have also tried a variety of solutions here and on other sites, including:

Prior to this problem I was seeing the LNK2019 errors described on this gamedev topic. That was solved by adding the lib to the additional dependencies in the project, but introduced the LNK2005 errors.

If it helps, the project builds in OS X; however, the libraries somewhat differ for Windows (dylib in OS X vs lib/dll in Win).

Can anyone help me to resolve these errors?

Community
  • 1
  • 1
morasta
  • 131
  • 12
  • I may have resolved SOME of these thanks to [this thread](http://social.msdn.microsoft.com/Forums/vstudio/en-US/ab51c229-4e70-46c0-a6c2-c5dfcd0630f5/warning-c4273-myclassmymethod-inconsistent-dll-linkage?forum=vclanguage). I added the `#define MYCLASS_API __declspec(dllexport)` to ftgl.h. Now I have a bunch of LIBCD.lib LNK2005 errors. If I compile it as /MD then I get conflicts with MSVCRT.lib. If I change /MD then LIBCD.lib conflicts with LIBCMTD.lib. ARGH! – morasta Jan 06 '14 at 01:10

1 Answers1

1

Make sure you lib are generated with same runtime library option under code generation

  • /MD and /MDd is for multi-threaded (debug)
  • /MT and /MTd is for multi-threaded DLL (debug)

All projects that have dependency with each other should has same option.


Also, you might have LIBCMT confliction if import static lib that is built with /MD and /MDd. Add LIBCMT into ignore libraries for linker can avoid this problem.

Xin Huang
  • 1,250
  • 1
  • 13
  • 26
  • Bingo, that did it. I'm pretty sure the glui lib was doing that. I recompiled it from source paying close attention to that and now it's all building. Thanks! – morasta Jan 06 '14 at 22:00