4

I'm developing a small Application using a QWidget and statically linking Qt 5.6. I'm using VS12 at moment.

#include <QMainWindow>
#include <QApplication>

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

  return a.exec();
}

It compiles fine but I'm getting linker errors.

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)

I have included the following libs:

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

And the funny thing is that if use QtCreator it compiles,links and runs just fine. What I saw is that QtCreator adds the following compile flags:

-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=

I tried them in my project but it does not change anything. What am I missing? What do I need to make the program link?

Jaa-c
  • 5,017
  • 4
  • 34
  • 64
Felix Schindler
  • 127
  • 1
  • 5
  • Is QMainWindwo just a misprint? What about CreateTLSIndex, Attribute - are they your custom classes and functions – demonplus Aug 02 '16 at 07:54
  • The included libs are release versions; the linker errors are about a debug lib. You should check your configuration in debug mode (I guess it's the same, but until checked...). How did you create your visual projects? qmake, cmake, by hand? Where does your static build from Qt comme from? Please edit your question with these details – rocambille Aug 02 '16 at 08:17
  • QMainWindwo was just a typo. I'm using the debug libs. I corrected that. CreateTLSIndex seems to part of the angle library which is part of Qt. The VS project was created by hand. The static Qt build comes from a local directory and lib path is correct. I double checked that. – Felix Schindler Aug 02 '16 at 08:39
  • 1
    [This question](http://stackoverflow.com/questions/22355570/building-a-static-version-of-qt-5-2-1-with-visual-studio-2013) may be related. – nonsensickle Aug 02 '16 at 08:44
  • Thanks @nonsensickle that got me in teh right direction. – Felix Schindler Aug 02 '16 at 11:25
  • Would you mind mentioning, in your question, if you have the [Visual Studio Add-in for Qt](http://doc.qt.io/vs-addin/) installed? – nonsensickle Aug 03 '16 at 12:35

2 Answers2

1

I found it. This is the list of libs you need to make it work:

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 is not needed. I still have no idea why QtCreator knows what libs are needed and why VS2013 does not. Thanks for your help.

Felix Schindler
  • 127
  • 1
  • 5
  • VS2013 knows nothing about Qt unless you use the Qt add-in :) – Kuba hasn't forgotten Monica Aug 02 '16 at 14:38
  • Pointing out, more clearly, which libraries you've added would help others who have the same problem. I would recommend prefixing them with a `+` symbol. The libraries that you've added, w.r.t. the ones listed in the original question, are `preprocessord.lib`, `translatord.lib`, `d3d9.lib` and `dxguid.lib`. You also seem to have removed `Qt5Cored.lib` which may or may not be intentional and deserves a mention in the answer as well. – nonsensickle Aug 03 '16 at 08:33
0

As far as I can tell the linker is complaining about this line of code. Looking at what that file is including seems to suggest dependence on libANGLE.

After a lot of Googling I found that CreateTLS() seems to be defined in libANGLE common, which can be found here.

I'm not sure in which particular Lib or DLL those definitions end up but looking into the build scripts would definitely reveal it (sorry, I don't have time to do that atm). But the symbols in the original question are definitely in one of the Libs provided by libANGLE.

this page suggests that all you need to do is add libEGLd.lib and libGLESv2.lib to your linker line, which is already the case, but you should check that you also have the DLLs too. Note point 3, quoted from the linked page, below:

  1. Copy libEGL.dll and libGLESv2.dll from the build output directory (see Building ANGLE) into your application folder.

If you add the DLLs to your solution you can automate copying them to the destination directory..

Community
  • 1
  • 1
nonsensickle
  • 4,438
  • 2
  • 34
  • 61