Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Static Qt deployment on Windows 7
Forum Updated to NodeBB v4.3 + New Features

Static Qt deployment on Windows 7

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
3 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rengan
    wrote on last edited by Rengan
    #1

    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: http://wiki.qt.io/Deploy_an_Application_on_Windows).
    My objective is to have zero other files than my executable (although not mandatory).
    My CMakeList is the following:

    project(hello_world)
    
    set(CMAKE_PREFIX_PATH "C:/msys64/home/Rengan/opencv310/mybuild_static/install")
    find_package(Qt5Core)
    find_package(Qt5Gui)
    find_package(Qt5Widgets)
    find_package(Qt5Test)
    find_package(Qt5Concurrent)
    find_package(OPENCV REQUIRED)
    cmake_minimum_required(VERSION 2.8)
    INCLUDE_DIRECTORIES("C:/msys64/home/Rengan/opencv310/mybuild_static/install/include")
    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 !

    Rengan

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rengan
        wrote on last edited by
        #3

        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 https://cmake.org/pipermail/cmake/2015-March/060069.html) 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: https://www.mail-archive.com/cmake%40cmake.org/msg51188.html
        I hope this will help, I will try it myself.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved