How to add opencv DLL on Windows to QTCreator project? - qt

I've built opencv and added these lines to .pro file:
INCLUDEPATH += C:/opencv-3.4.1/build/install/include
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_core341d.lib
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_highgui341d.lib
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_imgcodecs341d.lib
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_imgproc341d.lib
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_features2d341d.lib
now if I start the project, it links successfully but fails to start:
Starting C:\Users\steve\Documents\build-qttest4-Desktop_Qt_5_11_0_MSVC2015_64bit-Debug\debug\qttest4.exe...
The program has unexpectedly finished.
The process was ended forcefully.
Can I somehow tell QTCreator to add DLL files to put opencv DLL files to build-qttest4-Desktop_Qt_5_11_0_MSVC2015_64bit-Debug folder?

Here is a solution (which doesn't match top google search tutorial):
INCLUDEPATH += C:/opencv-3.4.1/build/install/include
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_core341d.lib
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_highgui341d.lib
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_imgcodecs341d.lib
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_imgproc341d.lib
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_features2d341d.lib
LIBS += -L"C:/opencv-3.4.1/build/bin/Debug"
and don't forget to run Build->Run qmake.

There are 2 ways to use DLL in some Windows Application
Use WinAPI LoadLibrary function and GetProcAddress function.
Set inside a Qt PRO file a location of LIB file that will tell to application that binary code is in YourLibraryName.DLL. But when you run debugger, application doesn't know where is DLL. One of possible solutions is to put full path to opencv DLL folder to PATH environment variable in windows Control Panel

Related

Qt creator: include path for external lib not found

I'm trying to add net-snmp lib to my project using win7 + cygwin:
Project file seems to contain valid lib and path entries:
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/C:/usr/lib/
-lnetsnmp else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/C:/usr/lib/ -lnetsnmpd
INCLUDEPATH += $$PWD/C:/usr/include DEPENDPATH += $$PWD/C:/usr/include
But I can't build the project, because include file is not found, also it exists under given directory physically (c:/usr/include/net-snmp/net-snmp-config.h)
../snmptest1221313123/main.cpp:1:38: fatal error: net-snmp/net-snmp-config.h: No such file or directory
#include
I've read all "add external lib" topics, but it doesn't help to solve this.
Re-running qmake, re-opening Qt creator, or running qmake -r from terminal doesn't help neither.
Remove $$PWD/ (both from include and libs) and try again: run qmake and rebuild.

Linking dll to c++ in qt for reading .mat files

I am using Qt Creator 2.4.1(Based on Qt 4.7.4) ..
Now I want to open the .mat file which I got from Matlab.
I am using the basic function matOpen
Initially, I knew the headers required. They are mat.h, matrix.h and tmw.h.
Now, before running the code, I need to link the libraries. The required libraries as far as I know are libmat.dll and libmw.dll . I added them to the .pro file as follows.
QT += core
QT -= gui
TARGET = mat_open_test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
HEADERS += \
mat.h \
matrix.h \
tmwtypes.h
LIBS += -L"C:\Users\skanduri\Documents\C ++\mat_open_test-build-desktop- Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug\libmat.dll"
LIBS += -L"C:\Users\skanduri\Documents\C ++\mat_open_test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug\libmx.dll"
Still I get error as : undefined reference to matOpen.. m sure the problem is with the linking.. But I dunno how to solve it. and the compiler Qt is using is MinGw .
You are specifying library path only, not the libraries itself. Try
LIBS += -L"C:\Users\skanduri\Documents\C ++\mat_open_test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug"
LIBS += -llibmx
LIBS += -llibmat

Run time error for a missing DLL which exists

I am writing a tool with Qt Creator which builds but immediately crashes with the message:
"The program can't start because pthreadVC2.dll is missing from your
computer. Try reinstalling the program to fix this problem".
Of course, the "pthreadVC2.dll" library is not missing (and is not corrupted, since it works with other projects), and it is located in the path specified in the Qt pro file:
# DeltaPlots.pro
TARGET = DeltaPlots
QT += core gui
CONFIG += console
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TEMPLATE = app
win32 {
INCLUDEPATH += S:\\3rdparty\\DFS.Infrastructure.ThreadingW \
S:\\3rdparty\\DFS.Infrastructure.File \
"C:\\path\\to\\boost\\boost_1_51_0"
win32-g++:LIBS += -L"S:\\lib\\" -lMyLib
win32-g++:LIBS += -L"S:\\3rdparty\\DFS.Infrastructure.File\\" -lDFS.Infrastructure.FileSystem
win32-g++:LIBS += -L"S:\\3rdparty\\DFS.Infrastructure.ThreadingW\\" -lDFS.Infrastructure.Threading -lpthreadVC2
}
SOURCES += MainWindow.cpp \
entrypoint.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui
OTHER_FILES += ProjectList.txt \
ImageList.txt
Platform:
Windows 7
MinGW
Qt 4.8.3
Qt Creator 2.6.0
[Edit: This answer refers to the original question]
Usually you would add
LIBS += -LS:/3rdparty/DFS.Infrastructure.ThreadingW \
-lpthreadVC2
This adds your library's folder as a library search path (Note the capital -L) and pthreadVC2.lib as a library to link against (lower case -l).
You do not need to add the .dll to the LIBS path, as the .dll is loaded at runtime.
But: This approach only works when the .lib is in the same folder as the .dll. I'm a bit surprised you have yours in different locations.
Maybe adding
LIBS += -LS:/3rdparty
would work, but I'm not sure about that.
In any event, you need to deploy the .dll with your .exe for releases.

Qt: Static linking of libraries

I'm developing a Qt application in windows. I have created a lib file in visual studio. I have included the header file containing function prototypes in my Qt App and also added lib file in .pro file as follows
win32: LIBS += -L$$PWD/../Lib/ -lCpLib
INCLUDEPATH += $$PWD/../Lib
DEPENDPATH += $$PWD/../Lib
win32: PRE_TARGETDEPS += $$PWD/../Lib/CpLib.lib
I called the functions from my Qt app. It shows compile error as "undefined reference"
Please help me.
Regards....
The specification of your LIBS is passing linker arguments in gcc format (i.e. using -L to specify the directory and -l to specify the library name).
As you have created your lib file in Visual Studio, you'll need to specify the full library name
e.g.
win32: LIBS += yourlibrary.lib
alternatively, recompile the libraries using MinGW

Howto use QCA(http://delta.affinix.com/qca/) with Qt4.7 (Qt Creator)?

I want to use the QCA Library with QT4.7 and QTCreator as IDE.
I downloaded the "qca-2.0.2-mingw" Version and try to link them in my ".Pro"-file:
QT += core
QT -= gui
LIBS += -L"\qca-2.0.2-mingw\lib\"
LIBS += -lqca2
CONFIG *= qt
CONFIG += console
CONFIG -= app_bundle
INCLUDEPATH += "\qca-2.0.2-mingw\include\QtCrypto"
INCLUDEPATH += "\qca-2.0.2-mingw\bin"
TARGET = untitled1
TEMPLATE = app
LINKAGE = -lqca
CONFIG(debug, debug|release) {
windows:LINKAGE = -lqcad
mac:LINKAGE = -lqca_debug
}
LIBS += $$LINKAGE
SOURCES += main.cpp
it compiles but when I run a HMAC sample, copied from this location, http://delta.affinix.com/docs/qca/mactest_8cpp-example.html#_a6
the application stuck with the following error:
Starting C:\Qt\2010.04\qt\untitled1\release\untitled1.exe...
C:\Qt\2010.04\qt\untitled1\release\untitled1.exe exited with code -1073741515
Commenting out some lines doesn't bring the effect. Even the first line of the HMAX Example, will lead to the results described above "QCA::Initializer init;"
I've tried the "qca-2.0.0-mingw" also, but the same effect occurres.
Greets and Thanks first,
Marco
If it builds, that's already good. If it doesn't start, usually DLLs are not found, at runtime. Try adding the path to the qca DLLs to your PATH. In creator you can configure that in the Run Environment section of your Run configuration (Project/Run Settings).

Resources