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

StackOverflow https://stackoverflow.com/questions/13307993

  •  28-11-2021
  •  | 
  •  

Domanda

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!

È stato utile?

Soluzione

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

Altri suggerimenti

Those specific linker errors happen if the "Treat WChar_T As Built in Type" property (found in C/C++ / Language in the property pages) is set to 'Yes' for the complication of the FTGL library and 'No' for the compilation of your application using the library.

The compiler preparing functions with "WChar_t const*" as the argument type in the FTGL library, but your program will be looking for "unsigned short *const", and so won't find any function with that signature.

To fix, change the property "Treat WChar_T As Built in Type" in your project so that it matches the setting in the FTGL library; clean and recompile and it should work.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top