Search code examples
c++ftgl

Creating object by using new operator causes unresolved external symbol error C++ FTGL


I'm using FTGL library in my Microsoft Visual Studio 2012, C++ project. I finally managed to properly link it to my project as I can properly render a font by using:

FTGLPixmapFont font("C:/Windows/Fonts/Arial.ttf");
font.Render("Hello world");

Everything seems to be ok until I try to create an object by using new operator:

FTGLPixmapFont* font = new FTGLPixmapFont("C:/Windows/Fonts/Arial.ttf"); // This causes error
font->Render("Hello world");

The code above produces this error:

AppLayer.obj : error LNK2001: unresolved external symbol "public: virtual float __thiscall FTFont::Advance(unsigned short const *,int,class FTPoint)" (?Advance@FTFont@@UAEMPBGHVFTPoint@@@Z)
1>AppLayer.obj : error LNK2001: unresolved external symbol "public: virtual class FTBBox __thiscall FTFont::BBox(unsigned short const *,int,class FTPoint,class FTPoint)" (?BBox@FTFont@@UAE?AVFTBBox@@PBGHVFTPoint@@1@Z)
1>AppLayer.obj : error LNK2001: unresolved external symbol "public: virtual class FTPoint __thiscall FTFont::Render(unsigned short const *,int,class FTPoint,class FTPoint,int)" (?Render@FTFont@@UAE?AVFTPoint@@PBGHV2@1H@Z)

I have completely no idea what can be reason for this. I'd really appreciate any answers.

Thanks!


Solution

  • It looks like you forgot to link a library, or to include a file in the build. This class inherits the class FTFont. Check that you correctly linked the library including this definition.

    In visual, you can just link the list by adding the .lib file to the project like if it is a cpp.

    If you link another project from the visual solution, check in the properties of your project if the dependance to the other project is set correctly.

    best