【问题标题】:QT 5.6 static unresolved external symbolQT 5.6 静态未解析的外部符号
【发布时间】:2016-08-02 07:49:12
【问题描述】:

我正在开发一个使用 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=

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

【问题讨论】:

  • QMainWindwo 只是印刷错误吗? CreateTLSIndex、Attribute 怎么样?它们是您的自定义类和函数吗
  • 包含的库是发布版本;链接器错误与调试库有关。您应该在调试模式下检查您的配置(我猜它是相同的,但直到检查...)。你是如何创建你的视觉项目的? qmake,cmake,手动? Qt 的静态构建来自哪里?请使用这些详细信息编辑您的问题
  • QMainWindwo 只是一个错字。我正在使用调试库。我纠正了这一点。 CreateTLSIndex 似乎是 Qt 一部分的角度库的一部分。 VS 项目是手工创建的。静态 Qt 构建来自本地目录,并且 lib 路径是正确的。我仔细检查了。
  • This question 可能是相关的。
  • 感谢@nonsensickle 让我朝着正确的方向前进。

标签: c++ qt


【解决方案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 不知道。 感谢您的帮助。

【讨论】:

  • VS2013 对 Qt 一无所知,除非你使用 Qt 插件 :)
  • 更清楚地指出,您添加的哪些库可以帮助遇到同样问题的其他人。我建议在它们前面加上 + 符号。您添加的库,w.r.t.原始问题中列出的是preprocessord.libtranslatord.libd3d9.libdxguid.lib。您似乎还删除了Qt5Cored.lib,这可能是有意的,也可能不是有意的,也值得在答案中提及。
【解决方案2】:

据我所知,链接器在抱怨this line of code。查看what that file is including 似乎暗示对libANGLE 的依赖。

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

我不确定这些定义最终会出现在哪个特定的 Lib 或 DLL 中,但查看构建脚本肯定会发现它(抱歉,我没有时间做那个 atm)。但原问题中的符号肯定在 libANGLE 提供的其中一个库中。

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 2020-07-01
    • 2012-12-13
    • 2020-04-02
    相关资源
    最近更新 更多