QT 5.6静态未解析的外部符号

时间:2016-08-02 07:49:13

标签: c++ qt

我正在使用QWidget开发一个小型应用程序并静态链接Qt 5.6。我现在正在使用VS12。

#include <QMainWindow>
#include <QApplication>

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  QMainWindow w;
  w.show();

  return a.exec();
}

它编译得很好,但我收到链接器错误。

1>libGLESv2d.lib(global_state.obj) : error LNK2019: unresolved external symbol "unsigned long __cdecl CreateTLSIndex(void)" (?CreateTLSIndex@@YAKXZ) referenced in function "struct A0x6526a104::Current * __cdecl `anonymous namespace'::GetCurrentData(void)" (?GetCurrentData@?A0x6526a104@@YAPAUCurrent@1@XZ)
1>libGLESv2d.lib(global_state.obj) : error LNK2019: unresolved external symbol "bool __cdecl DestroyTLSIndex(unsigned long)" (?DestroyTLSIndex@@YA_NK@Z) referenced in function _DllMain_ANGLE@12
1>libGLESv2d.lib(global_state.obj) : error LNK2019: unresolved external symbol "bool __cdecl SetTLSValue(unsigned long,void *)" (?SetTLSValue@@YA_NKPAX@Z) referenced in function "struct A0x6526a104::Current * __cdecl `anonymous namespace'::AllocateCurrent(void)" (?AllocateCurrent@?A0x6526a104@@YAPAUCurrent@1@XZ)
1>libGLESv2d.lib(global_state.obj) : error LNK2019: unresolved external symbol "void * __cdecl GetTLSValue(unsigned long)" (?GetTLSValue@@YAPAXK@Z) referenced in function "void __cdecl `anonymous namespace'::DeallocateCurrent(void)" (?DeallocateCurrent@?A0x6526a104@@YAXXZ)
1>libGLESv2d.lib(Program.obj) : error LNK2019: unresolved external symbol "bool __cdecl sh::InterpolationTypesMatch(enum sh::InterpolationType,enum sh::InterpolationType)" (?InterpolationTypesMatch@sh@@YA_NW4InterpolationType@1@0@Z) referenced in function "private: static bool __cdecl gl::Program::linkValidateVaryings(class gl::InfoLog &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,struct sh::Varying const &,struct sh::Varying const &)" (?linkValidateVaryings@Program@gl@@CA_NAAVInfoLog@2@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABUVarying@sh@@2@Z)
1>libGLESv2d.lib(Program.obj) : error LNK2019: unresolved external symbol "public: struct sh::ShaderVariable & __thiscall sh::ShaderVariable::operator=(struct sh::ShaderVariable const &)" (??4ShaderVariable@sh@@QAEAAU01@ABU01@@Z) referenced in function "private: bool __thiscall gl::Program::linkAttributes(class gl::InfoLog &,class gl::AttributeBindings const &,class gl::Shader const *)" (?linkAttributes@Program@gl@@AAE_NAAVInfoLog@2@ABVAttributeBindings@2@PBVShader@2@@Z)
1>libGLESv2d.lib(Program.obj) : error LNK2019: unresolved external symbol "public: __thiscall sh::Attribute::Attribute(void)" (??0Attribute@sh@@QAE@XZ) referenced in function "public: __thiscall gl::Program::Program(class rx::ProgramImpl *,class gl::ResourceManager *,unsigned int)" (??0Program@gl@@QAE@PAVProgramImpl@rx@@PAVResourceManager@1@I@Z)
1>libGLESv2d.lib(Program.obj) : error LNK2019: unresolved external symbol "public: __thiscall sh::Attribute::~Attribute(void)" (??1Attribute@sh@@QAE@XZ) referenced in function "public: __thiscall gl::Program::Program(class rx::ProgramImpl *,class gl::ResourceManager *,unsigned int)" (??0Program@gl@@QAE@PAVProgramImpl@rx@@PAVResourceManager@1@I@Z)
1>libGLESv2d.lib(ProgramImpl.obj) : error LNK2001: unresolved external symbol "public: __thiscall sh::Attribute::~Attribute(void)" (??1Attribute@sh@@QAE@XZ)
1>libGLESv2d.lib(Program.obj) : error LNK2019: unresolved external symbol "public: struct sh::Attribute & __thiscall sh::Attribute::operator=(struct sh::Attribute const &)" (??4Attribute@sh@@QAEAAU01@ABU01@@Z) referenced in function "void __cdecl std::_Fill<struct sh::Attribute *,struct sh::Attribute>(struct sh::Attribute *,struct sh::Attribute *,struct sh::Attribute const &)" (??$_Fill@PAUAttribute@sh@@U12@@std@@YAXPAUAttribute@sh@@0ABU12@@Z)

我已经包含以下库:

winmm.lib
imm32.lib
Ws2_32.lib
opengl32.lib
Qt5Guid.lib
Qt5Widgetsd.lib
qtpcred.lib
qtharfbuzzngd.lib
Qt5PlatformSupportd.lib
qwindowsd.lib
libEGLd.lib
libGLESv2d.lib
qtfreetyped.lib
Qt5Cored.lib

有趣的是,如果使用QtCreator它编译,链接和运行就好了。 我看到的是QtCreator添加了以下编译标志:

-DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_OPENGL_ES_2 -DQT_OPENGL_ES_2_ANGLE -DQT_OPENGL_ES_2_ANGLE_STATIC -DGL_APICALL= -DEGLAPI=

我在我的项目中尝试了它们,但它没有改变任何东西。 我错过了什么?我需要做什么才能使程序链接?

2 个答案:

答案 0 :(得分:1)

我找到了。这是使其工作所需的库列表:

winmm.lib
imm32.lib
Ws2_32.lib
Qt5Guid.lib
Qt5Widgetsd.lib
qtpcred.lib
qtharfbuzzngd.lib
Qt5PlatformSupportd.lib
qwindowsd.lib
libEGLd.lib
libGLESv2d.lib
qtfreetyped.lib
Qt5Cored.lib
+ preprocessord.lib
+ translatord.lib
+ d3d9.lib
+ dxguid.lib

不需要opengl32.lib。 我仍然不知道为什么QtCreator知道需要哪些库以及为什么VS2013不需要。 谢谢你的帮助。

答案 1 :(得分:0)

据我所知,链接器正在抱怨this line of code。查看what that file is including似乎表明依赖于libANGLE

经过大量谷歌搜索,我发现了CreateTLS() seems to be defined in libANGLE common,可以找到here

我不确定这些定义最终会在哪个特定的Lib或DLL中查找,但是查看构建脚本肯定会显示它(抱歉,我没时间做那个atm)< / em>的。但原始问题中的符号肯定是由libANGLE提供的一个Lib。

this page表示您需要做的就是将libEGLd.liblibGLESv2.lib添加到链接器行,已经是这种情况,但您应该检查是否也有DLL 。注意第3点,quoted from the linked page,下面:

  
      
  1. 将libEGL.dll和libGLESv2.dll从构建输出目录(请参阅构建ANGLE)复制到应用程序文件夹中。
  2.   

如果您将DLL添加到解决方案中,您可以automate copying them to the destination directory.