Important: Please read the Qt Code of Conduct -

Static Qt deployment on Windows 7

  • Dear all,

    I code a static-OpenCV program in QtCreator linked with Qt static (obtained via msys2). As soon as OpenCV needs Qt, the program crash (both in QtCreator and in Windows) with the famous error: "This application failed to start because it could not find or load the Qt platform plugin "windows".". Otherwise, when I ensure there is no call to any Qt function, OpenCV runs just fine.

    Most of the solutions I have found so far are about the dynamic deployment under Windows. But I fail to find the solution for my case, after having tried some of them (such as this one:
    My objective is to have zero other files than my executable (although not mandatory).
    My CMakeList is the following:

    set(CMAKE_PREFIX_PATH "C:/msys64/home/Rengan/opencv310/mybuild_static/install")
    find_package(OPENCV REQUIRED)
    cmake_minimum_required(VERSION 2.8)
    aux_source_directory(. SRC_LIST)
    add_executable(${PROJECT_NAME} ${SRC_LIST})
    set(CMAKE_EXE_LINKER_FLAGS "-static")
    target_link_libraries( hello_world ${OpenCV_LIBS} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test Qt5::Concurrent)

    And the code is simple:

    #include <iostream>
    #include <opencv2/opencv.hpp>
    using namespace std;
    using namespace cv;
    int main(int argc, char *argv[])
        Mat a = Mat::zeros(10,10,CV_64FC1); // Does not need Qt
        cout << "Hello World!" << endl;
        cout << "a = " << a << endl; // Does not need Qt
        namedWindow( "w", 1); // Needs Qt and CRASH !
        return 0;

    Please thank you for any help !


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Plugins needs special handling when you use a static build. See this chapter of Qt's documentation.

    Also, don't forget the licensing implication when using a static build of Qt.

  • Thank you for the link. If I used directly Qmake it would be practical, but through CMake it seems to become much more complicated.
    There have been some discussions about this topic on the CMake forum (such as here and the solutions are basically to patch Qt to make it work.
    Nevertheless, an alternative solution is to patch CMake to deal with static plugin:
    I hope this will help, I will try it myself.

Log in to reply