Building A static version of Qt 5.2.1 with Visual

2019-03-20 07:41发布

问题:

I have been trying for a few days now to build a static version of Qt with Visual Studio 2013. I just cannot figure out what I did wrong.

System:

  • Windows 7 64 bit
  • Visual Studio 2013 (Visual Studio 2012 is still installed)
  • Perl is installed (ActivePerl-5.18.2.1801-MSWin32-x64-297964.msi)
  • Python is installed (python-2.7.6.amd64.msi)
  • Direct X 10 SDK is installed (DXSDK_Jun10.exe I had to use this workaround)
  • Downloaded Qt 5.2.1
  • Downloaded Qt 5.3.0 alpha

What I did multiple time:

  • Extract the sources in a temp folder (C:\QtSrc)
  • Delete qtwebkit and qtwebkit-examples directories

For each folder I launched a Visual Studio x86 command line and ran:

  • cd C:\QtSrc
  • configure -c++11 -mp -debug-and-release -static -angle -nomake tests -nomake examples -prefix C:\Qt\5.2.1\msvc2013 -platform win32-msvc2013
  • nmake
  • nmake install

This was always sucessfull for every variations of -static vs -shared or Qt 5.2.1 vs Qt 5.3.0 alpha that I tried.

In Qt Creator

I can register the various Kits, compile and launch any example using the shared Qt library. The examples using the static Qt library on the other hand never compiled. The error always looks like this: LNK1104: cannot open file 'C:/Qt/5.3.0/msvc2013-static/lib/translator_common.lib'. The problem is that the file is missing (either translator_commond.lib in debug mode or translator_common.lib in release mode)

In Visual Studio 2013 (with Visual Studio Addin 1.2.3 alpha)

I can add the Qt version and change the Qt version of my solution. If can compile and run a very simple program like this one using the shared version of Qt:

#include <QtCore>
#include <QtGui>
#include <QtWidgets>

Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);

int main(int argc,char*argv[]){
    QApplication app(argc,argv);
    QMessageBox::critical(nullptr,"Hello","Hello Qt!");
    return 0;}

I get unresolved external linker errors when using the static version of Qt:

1>libGLESv2d.lib(Shader.obj) : error LNK2019: unresolved external symbol _ShInitialize referenced in function "private: void __thiscall gl::Shader::initializeCompiler(void)" (?initializeCompiler@Shader@gl@@AAEXXZ)
1>libGLESv2d.lib(Shader.obj) : error LNK2019: unresolved external symbol _ShFinalize referenced in function "public: static void __cdecl gl::Shader::releaseCompiler(void)" (?releaseCompiler@Shader@gl@@SAXXZ)
1>libGLESv2d.lib(Shader.obj) : error LNK2019: unresolved external symbol _ShInitBuiltInResources referenced in function "private: void __thiscall gl::Shader::initializeCompiler(void)" (?initializeCompiler@Shader@gl@@AAEXXZ)
1>libGLESv2d.lib(Shader.obj) : error LNK2019: unresolved external symbol _ShConstructCompiler referenced in function "private: void __thiscall gl::Shader::initializeCompiler(void)" (?initializeCompiler@Shader@gl@@AAEXXZ)
1>libGLESv2d.lib(Shader.obj) : error LNK2019: unresolved external symbol _ShDestruct referenced in function "public: static void __cdecl gl::Shader::releaseCompiler(void)" (?releaseCompiler@Shader@gl@@SAXXZ)
1>libGLESv2d.lib(Shader.obj) : error LNK2019: unresolved external symbol _ShCompile referenced in function "protected: void __thiscall gl::Shader::compileToHLSL(void *)" (?compileToHLSL@Shader@gl@@IAEXPAX@Z)
1>libGLESv2d.lib(Shader.obj) : error LNK2019: unresolved external symbol _ShGetInfo referenced in function "protected: void __thiscall gl::Shader::compileToHLSL(void *)" (?compileToHLSL@Shader@gl@@IAEXPAX@Z)
1>libGLESv2d.lib(Shader.obj) : error LNK2019: unresolved external symbol _ShGetInfoLog referenced in function "protected: void __thiscall gl::Shader::compileToHLSL(void *)" (?compileToHLSL@Shader@gl@@IAEXPAX@Z)
1>libGLESv2d.lib(Shader.obj) : error LNK2019: unresolved external symbol _ShGetObjectCode referenced in function "protected: void __thiscall gl::Shader::compileToHLSL(void *)" (?compileToHLSL@Shader@gl@@IAEXPAX@Z)
1>libGLESv2d.lib(Shader.obj) : error LNK2019: unresolved external symbol _ShGetInfoPointer referenced in function "protected: void __thiscall gl::Shader::compileToHLSL(void *)" (?compileToHLSL@Shader@gl@@IAEXPAX@Z)

Despite all my efforts I was unable to find which lib to include to resolve those missing symbols.

Do you have any idea what I have done wrong ?

回答1:

There is a bug in make install when using -angle and -static.

You can find the bug report here.

A simple workaround is to add a few copy at the end of the build process:

copy qtbase\lib\translator_common.lib C:\Qt\5.3.0\msvc2013-static\lib\
copy qtbase\lib\translator_common.prl C:\Qt\5.3.0\msvc2013-static\lib\
copy qtbase\lib\translator_commond.lib C:\Qt\5.3.0\msvc2013-static\lib\
copy qtbase\lib\translator_commond.prl C:\Qt\5.3.0\msvc2013-static\lib\

copy qtbase\lib\translator_hlsl.lib C:\Qt\5.3.0\msvc2013-static\lib\
copy qtbase\lib\translator_hlsl.prl C:\Qt\5.3.0\msvc2013-static\lib\
copy qtbase\lib\translator_hlsld.lib C:\Qt\5.3.0\msvc2013-static\lib\
copy qtbase\lib\translator_hlsld.prl C:\Qt\5.3.0\msvc2013-static\lib\

copy qtbase\lib\preprocessor.lib C:\Qt\5.3.0\msvc2013-static\lib\
copy qtbase\lib\preprocessor.prl C:\Qt\5.3.0\msvc2013-static\lib\
copy qtbase\lib\preprocessord.lib C:\Qt\5.3.0\msvc2013-static\lib\
copy qtbase\lib\preprocessord.prl C:\Qt\5.3.0\msvc2013-static\lib\

I hope this can help others.



回答2:

I happened to met with the same issue. I think the lib file you want to link against is translator_commond.lib. It contains the ANGEL symbols.

Here is how I found out the name of the library, in case it could be helpful when you met with other unresolved external symbols with Qt.

The dumpbin.exe tool is quite helpful here. You could execute dumpbin.exe /symbols some_lib.lib | findstr /c:"SOME_SYMBOL" to found whether a library contains or uses an symbol.

Since there are so many libs in Qt, I simply search for all *.lib files in Qt directory and copy them into a single directory, and then I do a batch search using the command below.

for %f in (*.lib) do echo %f >> symbols.txt && dumpbin /symbols %f | findstr /c:"SOME_SYMBOL" >> symbols.txt

Once done, you could check the generated symbols.txt and find out the name of the library that contains the symbol you are looking for.

BTW, since there are several huge libs, e.g. Qt5Core, Qt5Quick, etc, you probably would like to exclude them from searching.