简体   繁体   English

使用new运算符创建对象会导致无法解决的外部符号错误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. 我在Microsoft Visual Studio 2012 C ++项目中使用FTGL库。 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: 一切正常,直到我尝试使用new运算符创建对象为止:

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! 谢谢!

It looks like you forgot to link a library, or to include a file in the build. 您好像忘记了链接库,或在构建中包含文件。 This class inherits the class FTFont. 此类继承了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. 在可视化中,只需将.lib文件添加到项目中即可链接列表,就像它是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 最好

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. 如果将FTGL库的复杂性设置为“是”,将FTGL库的复杂性设置为“是”,而将“按类型处理Treat WChar_T内置属性”属性页中的C / C ++ / Language,则发生这些特定的链接器错误。您使用库的应用程序。

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. 编译器在FTGL库中使用“ WChar_t const *”作为参数类型准备函数,但是您的程序将查找“ unsigned short * const”,因此将找不到具有该签名的任何函数。

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; 要解决此问题,请在项目中更改属性“ Treat WChar_T As Built in Type”,使其与FTGL库中的设置匹配。 clean and recompile and it should work. 清理并重新编译,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM