Errors trying to compile OpenCV QT code from Github - c++

I'm new to the OpenCV / QT environment (and in programming in general). I'm trying to run this code:
https://github.com/Terranlee/Realtime_EVM
Can someone please tell me step by step what I need to install/compile in order to run this script on Windows 10? Not sure what versions to install or if it even matters.
I've tried following directions from here (https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows) but I keep getting 'undefined reference' errors which means I'm not referencing the libraries properly... or I need to edit the code somehow to point to my libraries but I'm not quite sure what to edit and how.
Thanks in advance and please excuse my noobieness!
-jay
Reply to answer
I compiled OpenCV using CMake per the wiki guide using the following commands:
mingw32-make -j 8
mingw32-make install
Once this was done, I opened Qt Creator and opened the Github EVM code by downloading the zip file then extracting it and opening the rvm.pro file.
Without making any changes, I tried to build the code and my first error was that it couldn't find "opencv_world310.dll" library.
I searched for it and found the file locally in the "E:\opencv\build\x64\vc14\bin" directory so I edited the rvm.pro file to look in that directory like so:
win32 {
OPENCVFOLDER = E:/_CODE_/_EXTERNAL_/OpenCV/my_git_build/
OPENCVVERSION = 310
INCLUDEPATH += E:\opencv\build\install\include
INCLUDEPATH += E:\opencv\build\x64\vc14\lib
CONFIG(release, debug|release) {
LIBS += -LE:\opencv\build\x64\vc14\lib
LIBS += -lopencv_world$${OPENCVVERSION}
}
CONFIG(debug, debug|release) {
DEFINES += DEBUG_MODE
LIBS += -LE:\opencv\build\x64\vc14\lib
LIBS += -lopencv_world$${OPENCVVERSION}d
}
This got rid of the initial error but then I get several 'undefined reference' issues afterward:
C:\Eulerian Real-Time OpenCV build\Realtime-Video-Magnification-master\build-rvm-Desktop_Qt_5_9_0_MinGW_32bit-Debug\debug\main.o:-1: In function `ZN2cv6StringD1Ev':
E:\opencv\build\include\opencv2\core\cvstd.hpp:664: error: undefined reference to `cv::String::deallocate()'
C:\Eulerian Real-Time OpenCV build\Realtime-Video-Magnification-master\build-rvm-Desktop_Qt_5_9_0_MinGW_32bit-Debug\debug\main.o:-1: In function `ZN2cv6StringaSERKS0_':
E:\opencv\build\include\opencv2\core\cvstd.hpp:672: error: undefined reference to `cv::String::deallocate()'
C:\Eulerian Real-Time OpenCV build\Realtime-Video-Magnification-master\src\main\threads\CaptureThread.h:42: error: undefined reference to `cv::VideoCapture::~VideoCapture()'
...... there are about 50 of these issues so I won't list them all.
Is it just a matter of correctly referencing the library?
In summary I'm just trying to run the Github code using Qt Creator, mingGW, CMake, & OpenCV. Please let me know how I need to edit the .pro file to link the library properly.
My OpenCV is in e:\opencv
Thanks again for the help and for your patience!
-Jay

There is very little info on what are the steps you are taking currently. Do you want to use Visual Studio / mingw? Here are some pointers:
You can open the pro file using Qt Creator
You can generate a Visual Studio compatible solution using qmake -spec <spec of the Visual Studio to use> -tp vc, to choose the spec see this answer.
With either of this you should have Qt includes/libraries set up.
The bad thing about the project is, that if you look at the .pro file, it explicitly uses Linux friendly include paths:
INCLUDEPATH += /usr/local/include \
/usr/local/include/opencv \
/usr/local/include/opencv2
LIBS += `pkg-config --libs opencv` -ldl
So, you will have to then add the include/library paths to OpenCV either inside Visual Studio or in the .pro file, if you are using Qt Creator. For example the link you used in your post on Qt/OpenCV has Windows friendly ones:
LIBS += D:\opencv-build\bin\libopencv_core320.dll
LIBS += D:\opencv-build\bin\libopencv_highgui320.dll
LIBS += D:\opencv-build\bin\libopencv_imgcodecs320.dll
LIBS += D:\opencv-build\bin\libopencv_imgproc320.dll
LIBS += D:\opencv-build\bin\libopencv_features2d320.dll
LIBS += D:\opencv-build\bin\libopencv_calib3d320.dll
So please explain in more detail what have you done so far, and which references (Qt/OpenCV) exactly are missing.

Related

undefined reference to `xlCreateBookW'

While using the libxl library in QT(c++) I got this error
undefined reference to `xlCreateBookW'
I have tried the setup in their website, https://www.libxl.com/setup.html
I added :
INCLUDEPATH = C:\libxl-4.0.4.0\include_cpp
LIBS += C:\libxl-4.0.4.0\lib\libxl.lib
to my project.pro and the file bin/libxl.dll to the project directory. It didn't work instead the error show up, how can I solve it please?
the code is in here https://www.libxl.com/home.html , i don't know i couldn't add it
i solved the problem actually the customer support guy i emailed him,
he told me to choose the bin which has the same version of my compiler (mine is 64bit) so you have to choose the bin and the lib also the same version and the path:
for my case (Qt_6_2_3_MinGW_64_bit compiler )
INCLUDEPATH = C:/libxl-4.0.4.0/include_cpp
LIBS += C:/libxl-4.0.4.0/lib64/libxl.lib
in the .pro file also you have to copy the libxl.dll from
C:\libxl-4.0.4.0\bin64 (for my case)
and thank you.

Undefined reference to opencv dnn on QtCreator

Error
Unable to link OpenCV DNN module with QtCreator : /home/joseph/Documents/dev/dnn_opencv/utils.cpp:52: error: undefined reference to `cv::dnn::dnn4_v20200609::Net::Net()
Context
Hi, I am trying to load some models with OpenCV DNN (OpenCV 4.4.0) module in order to do some classification/segmentation as part of a bigger project.
To do so I am using QtCreator (5.15.0) and gpp (10.1.0). OpenCV was built from source with the OpenCV-contrib.
My .pro file looks like that :
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
INCLUDEPATH += "/usr/local/include/opencv4"
LIBS += -L"/usr/local/lib/" \
-lopencv_highgui \
-lopencv_imgproc \
-lopencv_core
-lopencv_dnn
SOURCES += \
main.cpp \
utils.cpp
HEADERS += \
utils.hpp
The project is very simple so far, I am able to prompt images with OpenCV so it seems the usual libraries are being found. However whenever I use something within the DNN module I have this error : /home/joseph/Documents/dev/dnn_opencv/utils.cpp:52: error: undefined reference to `cv::dnn::dnn4_v20200609::Net::Net()
This is happening calling cv::dnn::Net net; using namespace or not.
I have noticed that in the file /usr/local/include/opencv4/opencv2/dnn/version.hpp that there is a flag #define OPENCV_DNN_API_VERSION 20200609 which corresponds to the dnn version where the Net class is to be found but I don't know where this could lead me.
I don't have much experience with Qmake and OpenCV so it's probably a simple fix but I'd appreciate some help. Thanks!
For those who are facing the same kind of issue, I managed to install it correctly and use it in QtCreator using the Cmake GUI and checking out all the correct flags. I believe it was an installation mistake regarding the OpenCV-contrib modules.
This link is a good tutorial to mark the correct flags : https://www.pyimagesearch.com/2018/08/17/install-opencv-4-on-macos/
Also, the weird error I had regarding the error: no matching function for call to std::shared_ptr<cv::Formatted>::shared_ptr(const char*&) was only due to a call to a print(...) instead of printf or cout.

Qt application cannot find a 3rd party DLL and crashes

I am trying to build an application in QT that uses the libmodbus library. I am using MinGW 5.3 (Windows 7). The application will build without an error, but crashes when it attempts to run. The debug message says:
During startup program exited with code 0xc0000135
If I double-click the created executable file, there is an error that says:
libmodbus-5.dll is missing
from my computer.
Libmodbus was built with the same compiler. The include files are located in ../../codelibrary/MinGW63/libmodbus-master/src and the linker files are located in ../../codelibrary/QtMinGW53/libmodbus-master/src/.libs (.libs folder has both libmodbus.dll.a and libmodbus-5.dll).
If I add this library with Qt's 3rd party library wizard, then I get the following in my .pro file:
win32: LIBS += -L$$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src/.libs/ -llibmodbus.dll
INCLUDEPATH += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src
DEPENDPATH += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src
win32:!win32-g++: PRE_TARGETDEPS += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src/.libs/libmodbus.dll.lib
else:win32-g++: PRE_TARGETDEPS += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src/.libs/liblibmodbus.dll.a
This gives me the error:
-1: error: No rule to make target '../../codelibrary/MinGW63/libmodbus-master/src/.libs/liblibmodbus.dll.a', needed by 'debug\QTRosemount.exe'. Stop.
I then tried changing the .pro file to:
LIBS += -L$$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src/.libs/libmodbus-5.dll
INCLUDEPATH += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src
DEPENDPATH += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src
PRE_TARGETDEPS += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src/.libs/libmodbus.dll.a
This is when it will build without error and crash right away with code 0xc0000135 and a missing libmodbus-5.dll. I have tried many variations of the .pro paths that get this same error.
Note: I have been able to run console applications in Codeblocks with this library, not sure what I am running into with Qt.
How to fix this?
you can use an INSTALL SET and append it to the INSTALL list, as shown in QT documentation and illustrated below:
documentation.path = /usr/local/program/doc
documentation.files = docs/*
INSTALLS += documentation
For convenience, you may also use QMAKE_PRE_LINK. Now that you have some options, you may find further information in stackoverflow, such as in posts like this one.
Alternatively, I found that DEPENDPATH was incorrect. I have a folder in libmodbus that this needs to point to:
DEPENDPATH += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src/.deps
The program compiles correctly with this changed

QtCreator unable to find Qxt headers on Linux?

I'm working on a Qt5/QtQuick/QML application that's supposed to use QxtGlobalShortcut for hotkey control when the application is hidden or out of focus. I've been developing it using QtCreator on Linux, and I'm not entirely familiar with Linux development so I may have missed something simple.
First off, I tried cloning the master branch of the Qxt git repo from here. But for some reason ./configure failed to create a makefile according to an error that I was getting from make and make install. I'm not very experienced in building other people's projects/libraries from source, and the output I was getting from ./configure wasn't specific enough for me to figure out what was going on..
So instead, I decided to grab libqxt-dev from (X)ubuntu's APT repo. After it finished installing I added these lines to the bottom of my QtCreator project file:
INCLUDEPATH = usr/include
CONFIG += qxt
QXT += core gui
After setting up a basic global shortcut based totally off the Qxt documentation's example. I got a few compilation errors. First of all, the Qxt seem to use:
#include <QxtGlobalShortcut>
But QtCreator couldn't find that file, so I changed it to this:
#include <qxt/QxtGui/QxtGlobalShortcut>
Now it could find the Global Shortcut class header, and QtCreator stopped grumbling at me. Unfortunately, upon compilation QtCreator shot out this error message:
/usr/include/qxt/QxtGui/qxtglobalshortcut.h:28: error: qxtglobal.h: No such file or directory
I think this is caused by a problem in my project's INCLUDE path or something, but even having tried changing my projects INCLUDE path to this:
INCLUDEPATH = usr/include
usr/include/qxt/QxtCore
usr/include/qxt/QxtGui
CONFIG += qxt
QXT += core gui
I still get the same error message that QxtGlobal.h (which is being #included in QxtGlobalShortcut.h) can't be found..
So, I'm really not sure what I've done wrong, and I'm out of ideas about how to fix this.
Hopefully someone can help me understand what step I've skipped so that I can continue coding! Thanks!
EDIT: Here's what I have for my entire Qt project .pro file:
TEMPLATE = app
QT += qml quick
SOURCES += main.cpp \
Gamepad.cpp \
Script.cpp \
System.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
HEADERS += \
Gamepad.h \
Script.h \
System.h
LIBS += -L/usr/lib -lSDL2
CONFIG += qxt
QXT += core gui
Everything before LIBS was automatically generated by QtCreator for my project. I added the LIBS, CONFIG, and QXT elements as per the user instructions for SDL2 and Qxt.
This is a big problem here:
INCLUDEPATH = usr/include
1) You are using relative path from the current working directory, so not /usr/include from the root of the filesystem.
2) You are deleting everything in the INCLUDEPATH because you set rather than append with +=.
3) It is unnecessary to add that line anyway since /usr/include will be looked up by default.
4) Even if it was not, you have #include "qxtglobal.h" instead of #include <qxtglobal.h>.
I would suggest to delete that line and then it should just work.

Building errors Qt creator with Tbb under Windows 8

I compiled TBB library as shown QtCreator and TBB under Windows
set the necessary paths to the library (. Dll)
INCLUDEPATH += "C:\Tbb\include"
LIBS += -L"C:\Tbb\build\windows_ia32_gcc_mingw_debug\" \
-tbb_debug.dll"
as shown, but build the project I have the following error image, any ideas?
Do not use extensions for libraries to link (they are added automagically)
Understand command line switches :) --library=namespec has a shorthand version -lnamespec. Following that you defined command line switch -t with an argument bb_debug.dll, which is nonsense :)
You should use -ltbb_debug