I have been struggling recently to get opencv to work with qt. At this moment my issue is this: It cant find the libraries. No matter what I do it says the same thing:
:-1: error: LNK1104: cannot open file 'opencv_improc245d.lib'
I included the bin in my path variable, and added each file to libs:
INCLUDEPATH += C:\\OpenCV-2.4.5\\opencv\\build\\include
LIBS += -LC:\\OpenCV-2.4.5\\mybuild\\lib\\Debug \
-lopencv_calib3d245d \
-lopencv_contrib245d \
-lopencv_core245d \
-lopencv_features2d245d \
-lopencv_flann245d \
-lopencv_gpu245d \
-lopencv_highgui245d \
-lopencv_improc245d \
-lopencv_legacy245d \
-lopencv_ ml245d \
-lopencv_ objdetect245d \
-lopencv_ ts245d \
-lopencv_ video245d
also, my opencv library is compiled from source for msvc2010 with qt enabled, and my qt is using msvc2010 as it's compiler.
Am I adding the libraries wrong or is something wrong with my includepath?
Look in the leftmost pane of Qt Creator. There is a Projects tab. (ctrl+5) should reach you there. Go to Build Environment. Click on Details to get list of System Environment Variables. Goto INCLUDE variable in the list. Select and click Edit. Add path_to_opencv/opencv/build/include.
[ path_to_opencv is the path where your opencv directory resides.]
Clean the project, run qmake and build the project again.
Related
My application builds and runs fine in Release mode. However, in Debug mode, my application crashes. When trying to use debugger to pinpoint the crash cause, such error is received:
Qt Creator unexpected CDB exit
The CDB process terminated
What could possibly be the problem cause?
UPDATE
I built and deployed the application in Debug mode and then tried to run the executable by command like:
C:\Users\m3\Documents\deployment_folder>.\application.exe
and I received this message:
The code execution cannot be proceed because tbb_debug.dll was not found. Reinstalling the program may fix this problem.
For some reason, tbb.dll can be found in Release mode but tbb_debug.dll cannot be found in debug mode. Although all TBB DLLs are in the same directory. Not sure why ...
UPDATE
I'm adding TBB to my project with QMake like this:
INCLUDEPATH += deps/tbb-2020.3-win/tbb/include
# Looks like absolute path works for LIBS, but NOT relative path
win32: CONFIG (release, debug|release): {
LIBS += -LC:\Users\m3\repos\myapp\deps\tbb-2020.3-win\tbb\lib\intel64\vc14 \
-ltbb \
-ltbb_preview \
-ltbbbind \
-ltbbmalloc \
-ltbbmalloc_proxy \
-ltbbproxy
} else: win32: CONFIG (debug, debug|release): {
LIBS += -LC:\Users\m3\repos\myapp\deps\tbb-2020.3-win\tbb\lib\intel64\vc14 \
-ltbb_debug \
-ltbb_preview_debug \
-ltbbbind_debug \
-ltbbmalloc_debug \
-ltbbmalloc_proxy_debug \
-ltbbproxy_debug
} else: unix: { # Linux and mac
# TODO: add correct path to LIBS +=
}
The problem is resolved by manually copying TBB DLLs next to the application executable.
Copy from ... /tbb-2020.3-win/tbb/bin/intel64/vc14/*.dll to executable location.
On why release mode worked
I think some 3rd party application has already added tbb.dll to may PATH environment variable. But tbb_debug.dll is not added to PATH by any application. Just a guess ...
I've visit these blogs
https://zahidhasan.wordpress.com/2014/08/19/qt-5-3-1-64-bit-mingw-windows/
How to link opencv in QtCreator and use Qt library
http://www.cnblogs.com/grandyang/p/4328896.html
All of them are using Mingw to compile Opencv through Cmake.
If I want to use Opencv in QT, is compiling with Mingw the only way?
I have this question because I already compiled my Opencv 2.4.11 with Visual Studio 2013(in Cmake---Visual Studio 12 2013 Win64),
when I follow the directions setting up the INCLUDEPATH and LIBS in QT
"C:\\opencv2.4.11\\opencv\\build\\include\\opencv"
"C:\\opencv2.4.11\\opencv\\build\\include\\opencv2"
-L"C:\\opencv2.4.11\\opencv\\build\\x64\\vc12\\lib" \
-lopencv_core2411 \
-lopencv_highgui2411 \
-lopencv_imgproc2411 \
-lopencv_features2d2411 \
-lopencv_calib3d2411 \
I get this error message:
C1083:Cannot open include file:'opencv2/opencv.hpp': No such file or directory
You can compile it with Visual Studio as well. The opencv includepaths already have the opencv2 part of it. So the correct includepath would only be:
C:\\opencv2.4.11\\opencv\\build\\include
I’m working on a project with opencv lib. I use Qt 4.8 on Windows 7 and it gives me an error when building the project:
mingw32-make.exe[1]: *** Access is denied.
. Stop.
mingw32-make.exe: *** [release] Error 2
19:05:06: The process "F:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project TraySystemtry (target: Desktop)
When executing build step 'Make'
The pro file:
QT += xml svg core gui
CONFIG += qt
VERSION = 0.3.0
TEMPLATE = app
INCLUDEPATH += D:\OpenCV\opencv\build\include
LIBS += -LD:\OpenCV\opencv_Build\bin\
-lopencv_core242 \
-lopencv_highgui242 \
-lopencv_imgproc242 \
-lopencv_features2d242 \
-lopencv_calib3d242 \
-lopencv_objdetect242
HEADERS += \
window.h \
aboutus.h \
abouttab.h \
developertab.h \
privacytab.h \
classificationhand.h \
keyssetup.h
SOURCES += \
window.cpp \
main.cpp \
aboutus.cpp \
abouttab.cpp \
developertab.cpp \
privacytab.cpp \
classificationhand.cpp \
keyssetup.cpp
RESOURCES += \
systray.qrc
I can’t figure out the problem.
I have the same problem. For mine, I resolved it just disabling the antivirus (Kaspersky). The antivirus was denying mingw32-make.
There are at least two possible causes:
The file you're trying to build is open/used (the program is running)
You don't have sufficient privileges (you don't have admin rights)
Cause #1 is often more likely than cause #2.
For me it usually means that the exe that I'm trying to compile is currently open (i.e., running). This often happens when I have it running in debug mode, then try to recompile.
I'm writing a small C++ program (with a GUI) with Qt Creator and compiling with MinGW. Everything works fine when I compile the project in debug mode but as soon as I move to release mode I get compiler errors:
undefined reference to 'std::out_of_range::~out_of_range()' thread.cpp
When I click on the error I also get:
File not found: thread.cpp
I have looked through my Boost installation and found thread.cpp and it should be on the include path for my project.
Any ideas?
EDIT: Here is my .pro file:
#-------------------------------------------------
#
# Project created by QtCreator 2012-08-10T12:09:39
#
#-------------------------------------------------
QT += core gui
TARGET = GeneDropWin
TEMPLATE = app
SOURCES += main.cpp \
genedrop.cpp \
mainbody.cpp \
biofunctions.cpp \
fileio.cpp \
settings.cpp
HEADERS += genedrop.h \
geneclasses.h \
paramclass.h \
mainbody.h \
biofunctions.h \
fileio.h \
geneclasses.h \
settings.h
FORMS += genedrop.ui \
settings.ui
#Stuff I've added
INCLUDEPATH += "C:\\Program Files\\boost_1_50_0"
LIBS += -L"C:\\Program Files\\boost_1_50_0\\stage\\lib" -lboost_thread-mgw46-mt-1_50 -lboost_system-mgw46-mt-1_50 -lboost_date_time-mgw46-mt-1_50 -lboost_chrono-mgw46-mt-1_50
CONFIG += static \
release
RESOURCES += \
NIABLogo.qrc
Ok, the problem is fixed but perhaps not completely understood. I fixed it by switching compiler to MSVC and changing the syntax for the linker options (e.g. -lboost_thread-mgw46-mt-1_50 -> -llibboost_thread-vc100-mt-1_50), compiles without an issue now. I will put forward my reasoning as to what I think may have been the problem but would appreciate a better answer if wrong:
Although I thought I had built the Boost libraries with MinGW when looking through the installation I found a number of folders mentioning msvc instead (e.g. ...boost\bin.v2\libs\date_time\build_msvc-10.0) which suggested to me that I had built it with MSVC.
The linker error claimed not to be able to find files associated with thread.cpp.
Looking at the thread folder of the build directory all the .obj and .lib files had msvc-10.0 folders in their path.
Thus I think that the MinGW compiler was looking for boost objects within a non-existent MinGW folder and so was failing. The fact that it worked under debug mode I guess relates to a less-constrained search for files.
I built OpenCV with CMake under Visual studio 10, copied the binaries to a /bin folder in the opencv directory. I have a simple OpenCV program with no syntax errors, but I am getting several errors such as "undefined reference to cv::imread". Why is this?
My .pro file has the following appended at the end of it:
INCLUDEPATH += C:/opencv/build/include/
LIBS += -LC:/opencv/build/x64/vc10/lib \
-lopencv_core231 \
-lopencv_highgui231 \
-lopencv_imgproc231 \
-lopencv_features2d231 \
-lopencv_calib3d231
Thanks
undefined reference instead of unresolved external symbol means you are probably using MinGW for your application, and you can't use gcc with a VC++ compiled C++ library.