Skip to content

Instantly share code, notes, and snippets.

@constructor-s
Created July 3, 2020 03:14
Show Gist options
  • Save constructor-s/0e940c6336ad8a4bdff5414db74012cc to your computer and use it in GitHub Desktop.
Save constructor-s/0e940c6336ad8a4bdff5414db74012cc to your computer and use it in GitHub Desktop.
How to use static Qt (5.12.8) on Windows 10 (qt5:x64-windows-static)

Compile static Qt

Use vcpkg with the following command:

vcpkg install qt5:x64-windows-static

Configure compiler

This is necessary for using any static libraries with vcpkg:

Configuration Properties/Vcpkg/Use static libraries: Yes

Configuration Properties/"C/C++"/Code Generation/Runtime Library: /MT for release, /MTd for debug (switch Conguration on top left) This is necessary because vcpkg compiles static libraries with /MT.

Hello World Code

#include <QtCore/QtPlugin>
#include <QtWidgets/QApplication>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QLabel>
#include <iostream>

int main(int argc, char* argv[])
{
    Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);

    std::cout << "Hello World!\n" << QT_VERSION_STR << "\n";

    QApplication application(argc, argv);
    QMainWindow mainWindow;
    QLabel* label = new QLabel(&mainWindow);
    label->setText("first line\nsecond line");
    mainWindow.show();

    return application.exec();
}

Linker

You will encounter many linker errors and Google each of them. I ended up with the following list:

Configuration Properties/Linker/Input/Additional Dependencies for release:

imm32.lib
winmm.lib
Ws2_32.lib
Version.lib
Netapi32.lib
iphlpapi.lib
userenv.lib
psapi.lib
CRYPT32.LIB
Wtsapi32.lib
Dwmapi.lib
"E:\vcpkg\installed\x64-windows-static\plugins\platforms\qwindows.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Core.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Gui.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Widgets.lib"

Configuration Properties/Linker/Input/Additional Dependencies for debug:

imm32.lib
winmm.lib
Ws2_32.lib
Version.lib
Netapi32.lib
iphlpapi.lib
userenv.lib
psapi.lib
CRYPT32.LIB
Wtsapi32.lib
Dwmapi.lib
"E:\vcpkg\installed\x64-windows-static\debug\plugins\platforms\qwindowsd.lib"
"E:\vcpkg\installed\x64-windows-static\debug\lib\Qt5Cored.lib"
"E:\vcpkg\installed\x64-windows-static\debug\lib\Qt5Guid.lib"
"E:\vcpkg\installed\x64-windows-static\debug\lib\Qt5Widgetsd.lib"

Reference

Many are accessible easily through English Google, but here are two key resources in foreign languages:

TODO

  1. CMake
  2. Compile UI files
  3. How to include directly e.g. <QApplication> instead of <QtWidgets/QApplication>
  4. Linker input path with environmental variables
@constructor-s
Copy link
Author

Another (crazy) list of dependencies:

E:\vcpkg\installed\x64-windows-static\lib\Qt5AxBase.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5AxContainer.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5AxServer.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Concurrent.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Core.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5DBus.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Designer.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Gui.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Help.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Multimedia.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5MultimediaWidgets.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Network.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5NetworkAuth.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5OpenGL.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5OpenGLExtensions.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5PrintSupport.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Qml.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Quick.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5QuickControls2.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5QuickTemplates2.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5QuickTest.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5QuickWidgets.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Sql.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Svg.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Test.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5UiTools.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Widgets.lib
E:\vcpkg\installed\x64-windows-static\lib\Qt5Xml.lib
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\ole32.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\oleaut32.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\user32.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\gdi32.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\advapi32.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\ws2_32.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\netapi32.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\uuid.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\winspool.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\comdlg32.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\dnsapi.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\iphlpapi.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\crypt32.lib"
E:\vcpkg\installed\x64-windows-static\lib\libssl.lib
E:\vcpkg\installed\x64-windows-static\lib\libcrypto.lib
secur32.lib
shell32.lib
crypt32.lib
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\mpr.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\userenv.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\version.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\kernel32.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\shell32.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\winmm.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\uxtheme.lib"
"E:\\Windows Kits\\10\\lib\\10.0.18362.0\\um\\x64\\dwmapi.lib"
E:\vcpkg\installed\x64-windows-static\lib\harfbuzz.lib
E:\vcpkg\installed\x64-windows-static\lib\freetype.lib
gdi32.lib
comdlg32.lib
oleaut32.lib
imm32.lib
winmm.lib
ws2_32.lib
ole32.lib
uuid.lib
user32.lib
advapi32.lib
E:\vcpkg\installed\x64-windows-static\lib\zlib.lib
E:\vcpkg\installed\x64-windows-static\lib\icuin.lib
E:\vcpkg\installed\x64-windows-static\lib\icutu.lib
E:\vcpkg\installed\x64-windows-static\lib\icuuc.lib
E:\vcpkg\installed\x64-windows-static\lib\icuio.lib
E:\vcpkg\installed\x64-windows-static\lib\icudt.lib
Advapi32.lib
E:\vcpkg\installed\x64-windows-static\lib\pcre2-16.lib
E:\vcpkg\installed\x64-windows-static\lib\double-conversion.lib
E:\vcpkg\installed\x64-windows-static\lib\bz2.lib
E:\vcpkg\installed\x64-windows-static\lib\libpng16.lib
kernel32.lib
winspool.lib
"E:\vcpkg\installed\x64-windows-static\plugins\platforms\qwindows.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5AccessibilitySupport.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5AxBase.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5AxContainer.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5AxServer.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Concurrent.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Core.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5DBus.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Designer.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5DesignerComponents.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5DeviceDiscoverySupport.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5EdidSupport.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5EventDispatcherSupport.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5FbSupport.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5FontDatabaseSupport.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Gui.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Help.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Multimedia.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5MultimediaQuick.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5MultimediaWidgets.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Network.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5NetworkAuth.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5OpenGL.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5OpenGLExtensions.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5PacketProtocol.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5PlatformCompositorSupport.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5PrintSupport.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Qml.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5QmlDebug.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Quick.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5QuickControls2.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5QuickParticles.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5QuickShapes.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5QuickTemplates2.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5QuickTest.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5QuickWidgets.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Sql.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Svg.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Test.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5ThemeSupport.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5UiTools.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Widgets.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5WindowsUIAutomationSupport.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Xml.lib"
Ws2_32.lib
Version.lib
Netapi32.lib
iphlpapi.lib
userenv.lib
psapi.lib
CRYPT32.LIB
Wtsapi32.lib
Dwmapi.lib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment