0

I just recently programmed a project in QT Creator framework which both uses QT libraries such as QT_Widget and also openCV libraries such as openCV_tracking . my project includes .ui , .pro , main.cpp and some classes with .h and .cpp files.

my .pro file is :

QT       += \
        core gui \
        concurrent widgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Version7
TEMPLATE = app

DEFINES += QT_DEPRECATED_WARNINGS

#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

CONFIG += \
   c++11 \
   cmdline

SOURCES += \
    main.cpp \
    mainwindow.cpp \
    videoprocessor.cpp \
    robottracker.cpp \
    robotdetector.cpp \
    obstaclesdetector.cpp \
    pathcapture.cpp

HEADERS += \
    mainwindow.h \
    videoprocessor.h \
    robottracker.h \
    robotdetector.h \
    obstaclesdetector.h \
    pathcapture.h

FORMS += \
    mainwindow.ui

# including openCV needed files
INCLUDEPATH += E:\\MyOpenCV\\install\\include
INCLUDEPATH += C:\\openCV\\opencv\\build\\include
LIBS += -LE:\\MyOpenCV\\install\\x64\\vc15\\lib \
           -lopencv_tracking430
LIBS += -LC:\\openCV\\opencv\\build\\x64\\vc15\\lib \
           -lopencv_world430

# Default rules for deployment.
 qnx: target.path = /tmp/$${TARGET}/bin
 else: unix:!android: target.path = /opt/$${TARGET}/bin
 !isEmpty(target.path): INSTALLS += target

it runs in QT creator with no problem ; but now i wanna share it with my team and for that I want to build a standalone exe file from it which statically links all libraries used in project. can someone please guide me how can I do that with QT Creator or some other options? in the internet there were some suggestions but none worked .

1 Answers1

0

I tried this a while ago but eventually gave up, although it definitely is possible.

The reason Qt hides how to do it so much is that they much prefer that people dynamically link to their libraries as it both allows users to update/change the Qt dll's as they please and (which I think is the real reason) it makes it more obvious that a developer is using their suite.

I will guide you in the direction I think should be taken, but I am not too sure how successful you will be unfortunately.

  1. First you need to build the actual Qt library statically. I will assume you are using the MinGW shipped with Qt Creator as your compiler. According to the following tutorial https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW , you can download the following powershell script (ensure you have powershell installed): https://sourceforge.net/p/qtlmovie/code/ci/v1.2.16/tree/build/windows-build-qt-static.ps1?format=raw. As long as you have Qt installed under C:\Qt, and a subdirectory called "Static" in this folder, you should be able to simply run this script and wait for Qt to build into that folder.

  2. Secondly, you need to link against the Qt libs in your application. Open Qt Creator, go to Tools > Options > "Build & Run". The Qt tutorial says the following:

Go to tab "Qt Versions". In the "qmake location" table, there must be an "Auto-detected" part and a "Manual" part. In the "Auto-detected" part, there should be one line named "Qt 5.5.0 MinGW 32bit C:\Qt\Qt5.5.0\5.5\mingw492_32\bin\qmake.exe". The "Manual" part is initially empty.

Click "Add", browse to C:\Qt\Qt5.5.0\bin and select "qmake.exe". The version name is automatically set to "Qt 5.5.0 (5.5.0)". You should set a more meaningful name such as "Qt 5.5.0 MinGW Static 32bit"

Then go to tab "Kits". Again, there must be an "Auto-detected" part and an initially empty "Manual" part. Click "Add". Set a meaningful name such as "Desktop Qt 5.5.0 MinGW Static 32bit". In the "Qt version" field, select your static environment, named "Qt 5.5.0 MinGW Static 32bit" if you followed the above advice.

  1. Click "Add Kit" in the upper left corner and select your static kit, named "Desktop Qt 5.5.0 MinGW Static 32bit" if you followed the above advice.

That should be it. Unfortunately I'm unable to try it out by myself, but that should be the general procedure. A lot of the tutorials seem long-winded, but generally if you follow them step-by-step they work out in the end.

Also, do note that they didn't refer to the "static" directory in the above instructions. I believe this is incorrect, and that is what they are actually referring to, so maybe give that a try instead, although I'm not sure.

Good luck!

Gary Allen
  • 1,218
  • 1
  • 13
  • 28
  • thank u about your answer, it helped alot .I did although not exactly what u said , but with some changes I could finally make a static linked QT project. but now when I include openCV to my project , I get an error which says "undefined reference to 'cv::* " for all opencv modules I used in project. there is nothing in the internet about it. help me please if you know what I should do. thanks. – AmirHossein Rasoulian Jun 23 '20 at 22:44
  • No problem! Don't forget to select best answer if I helped ;). Are you linking against the OpenCV libraries? You need to add LIBS += -L{path_to_opencv} -l{opencv_library_filename}. Check out this tutorial: https://stackoverflow.com/questions/47611221/add-opencv-library-to-every-qt-project – Gary Allen Jun 24 '20 at 09:41
  • yeah I did that , it actually works with original QT qmake.exe that is in the original QT folder (C:\\Qt\\5.14\\msvc17_x64\\bin ) and with msvc17 compiler ( the old configuraion I've used that creates dynamic linked app) , but when I create another kit that its qmake.exe is in C:\\Qt\\static\\bin , firstly I had to rename all libraries such as libQWidgets.a to QWIdgets.lib in its lib directory ( after that it worked ! ) and secondly It longer finds opencv modules ( undefined reference to ... ) . do you have any idea why is that happening? – AmirHossein Rasoulian Jun 24 '20 at 17:32
  • I believe that is because of MINGW , cause I tested on dynamic linked space but this time with mingw compiler , it reports that error as well. – AmirHossein Rasoulian Jun 24 '20 at 17:55