Qt and OpenCV static libraries conflict with each other - c++

I'm using Visual Studio 2010, OpenCV 2.4.5, and QT 5.0.2.
I'm trying to deploy my application by loading static libraries of OpenCV and QT.
The problem is that both of them contain zlib (compression library) internally.
So, when I compile the project, link error occurs, since symbols are conflicted as below.
zlibd.lib(zutil.obj) : error LNK2005: _z_errmsg is already defined in Qt5Cored.lib(zutil.obj).
However, both of OpenCV and QT do not provide static library without zlib.
What can I do?

Take a look at the OpenCV installation guide. It says, "You can use Qt as HighGUI backend on any platforms (Windows, Linux, Mac) by passing WITH_QT=ON to CMake when configuring OpenCV." The guide also has a link to a step-by-step guide.
So, do these steps and add WITH_QT=ON to your OpenCV configuration.

Related

OpenCV build with tesseract

I'm trying to build opencv-4.5.1 with tesseract-5.0.0 using cmake under Windows 10. First, I built tesseract with C++17 (by default) as static lib. Then, when configuring opencv, cmake issues the message:
Tesseract: YES (ver 5.0.0-alpha-20201231)
Can't use Tesseract (details: https://github.com/opencv/opencv_contrib/pull/2220)
Looking closely at the opencv flags I found that it was configured with C++11. Then I rebuilt tesseract with C++11 support, but this error persists. As a result, opencv is built, but when creating an OCRTesseract object, a message is displayed that tesseract was not found.
Then I tried the older tesseract-4.1.0 version. It is labeled LSTM. The error persisted.
What moment did I miss?

OpenCV Qt Setup with MS Visual C++ 2012 Compiler

Like the title says, I have been using Qt creator along with a kit that uses the Visual C++ 12.0 (x86_amd64) compiler and I have been trying to get openCV set up so that I can use that library in my project. I downloaded the most recent version of openCV (alpha 3.0.0) and have tried numerous ways of trying to link it to QT, but no matter what I try it fails.
I have tried looking at several tutorials that have been using Cmake to compile the source into binaries, but those have also failed. Since I am using the C++ 12 compiler, is it possible to just use the pre-compiled binaries that come with the download, or do I have to manually compile them? I downloaded it from the OpenCV site and tried to use cmake to compile the binaries, configured with the visual C++ 2012 compiler, but I have no idea where to go after those binaries are generated so that's why I have tried with the binaries you download straight from the site.
Any thoughts or links to tutorials are greatly appreciated, I just can't get this thing to work.
A few things I have tried have been adding
INCLUDEPATH += "C:\OpenCV-3.0.0\opencv\sources\include"
To link to cv.h, and I have these libraries linked because I tried linking all the ones I found in the pre compiled binaries
LIBS += "C:\OpenCV-3.0.0\opencv\build\x86\vc12\lib\opencv_ts300.lib"
"C:\OpenCV-3.0.0\opencv\build\x86\vc12\lib\opencv_ts300d.lib"
"C:\OpenCV-3.0.0\opencv\build\x86\vc12\lib\opencv_world300.lib"
"C:\OpenCV-3.0.0\opencv\build\x86\vc12\lib\opencv_world300d.lib"

OpenCV3.0 and Qt creator

I need to use OpenCV with Qt creator, and need some help with OpenCV.
My problem occurs when I run any example or .exe made with OpenCV, after I install OpenCV with CMake (and checking WITH_QT in the process).
For example with the examples included in the installation, when I try to open one I get the following error:
http://answers.opencv.org/upfiles/1413994743487541.png
That says: Procedure entry point not found in the dynamic links library
My S.O. is Windows 8.1, 64 bits
I have tried to reinstall Qt and install differents versions, but the error is the same ever.
But, if I install OpenCV with CMake and donĀ“t check WITH_QT, the examples works perfectly.
I dont know what else can I do!
Thanks!

OpenCV 2.4.3+ with libstdc++ for iOS?

I'm trying to include a recent version of OpenCV into an existing iOS project and am having linker errors because my XCode project is set to use libstdc++ and not libc++ / C++ 11 support.
I have seen several other people who have fixed their errors by enabling libc++. Examples:
Linker errors after upgrading Xcode to 4.5.2 and OpenCV to 2.4.3
How to resolve iOS Link errors with OpenCV
However, I NEED to use libstdc++ because I have other 3rd party libraries which are already compiled with the older stdlib (can't be changed). Is there a way to compile OpenCV 2.4.3+ without -stdlib=libc++ ? Are there special flags to pass to CMake? or to the build_framework.py script that comes in the ios folder of the OpenCV source code?
Alternatively, does anyone have a binary version available? It seems all downloadable from OpenCV assume libc++ / C++11.
In the source for openCV locate this file:
ios/cmake/Modules/Platform/iOS.cmake
Change this line:
set (CMAKE_CXX_FLAGS "-stdlib=libc++ -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden")
to:
set (CMAKE_CXX_FLAGS "-stdlib=libstdc++ -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden")
Compile using the python script
ios/build_framework.py
Then you should be good to go
I have just tried this on 2.4.3 source, swapped in the resulting framework on an existing project, changed the C++ standard library for the project to libstdc++ and it runs fine.
I am also working on a project using OpenCV and a 3rd party library which requires libstdc++.
As I just ran into this problem myself, I wanted to share what worked for me.
I was able to get OpenCV working by adding "libc++.dylib" to my project.
Build Phases -> "Link Binary with Libraries" -> "+" -> libc++.dylib
For reference, I am using OpenCV 2.4.9 (opencv-2.4.9) from opencv.org. I compiled it using the ios platform build_framework.py per the instructions in OpenCV's docs. No modification necessary.

build problems with Qt and opencv on Windows

I would like to create a gui application with Qt, using opencv on Windows XP. I used both Qt and opencv before, but never together. Long story short, I'm unable to get opencv work with Qt.
As on all the forums I searched there are just little pieces of information scattered around, usually with no answer, I summarize here all the steps I've taken.
Downloaded the Qt SDK (4.6.3) for Windows, and used it for some time, successfully.
Downloaded the opencv 2.3.1 megapack for Windows, complete with binaries. I managed to compile my Qt project including opencv successfully, but any opencv function call resulted in a crash. I read on some forums that the binaries in the Windows megapack don't support Qt, and I have to build opencv myself
I downloaded the latest version of CMake (2.8).
I downloaded the source of opencv from here: http://code.opencv.org/svn/opencv/branches/2.3/
I downloaded the source for the version of Qt I had (4.6.3)
I found my old version of visual Studio 2005
I created a VS2005 project with CMake, checking the support for Qt. (WITH_QT checked)
I built opencv in VS2005. It created most of the libraries, but not all. Highgui was among the failed ones. The problem: Qt\4.6.3\src\corelib\global\qconfig.h was not found. There was no qconfig.h at all in the source I downloaded! I found some templates qconfig-large.h, qconfig-small.h etc., so I renamed one of them to qconfig.h. Now I got a screen full of linker errors.
I downloaded the latest Qt source instead (4.8.1). Now there is a source file qbenchmark.h that includes QtTest/qbenchmarkmetric.h which cannot be found.
I gave up, and tried MinGW.
I downloaded the latest MinGW (2011.11.18)
I set CMake to generate a MinGW makefile, but I got the following error:
.
CMake Error at C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-g++.cmake:1 (INCLUDE):
include could not find load file:
C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-gcc.cmake
Call Stack (most recent call first):
C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/CMakeCXXInformation.cmake:59 (INCLUDE)
True, there is a Windows-g++.cmake file in the Modules/Platform directory, but it references Windows-gcc.cmake which does not exist!
Is there anyone who managed to build opencv with Qt support on Windows, and if yes, how?
Edit:
The problem is definitely with the Qt source. I managed to generate a MinGW makefile, and the build went all OK until it stopped in src/testlib/qtestsystem.h because there was an include for QtCore/qelapsedtimer.h which file is in a completely different directory! Does Qt release incomplete sources, or did I do something wrong?
Edit2
My torment continues. I cleaned everything and started anew. This time without even trying Visual Studio.
I downloaded the latest Qt libs with source (4.8.1)
I downloaded the latest MinGW (2011.11.18)
With CMake I successfully created a Makefile, and built it with MinGW. I got some shiny new libs (libopencv_core231, etv.). I was very happy, but how wrong I was to celebrate that soon!!
I downloaded the latest Qt SDK (strangely, it was 4.8.0, so I set Qt Creator to use the 4.8.1) and created a test program without opencv to see if it works. It worked!
I tried using opencv, just reading and displaying an image. It didn't work. exited with code -1073741511
I tried running the .exe directly, outside of Qt Creator. It complained of a missing libstdc++-6.dll
I did a search for it, and found on in my MinGW install (c:\mingw\bin, 958 KB), and one in my Qt install (c:\qt\mingw\bin, 793 KB) - this mingw came bundled with Qt.
I tried both, by copying them in the same folder where my .exe is, but neither worked. I got "The procedure entry point _ZNSt9exceptionD2Ev could not be located in the dynamic link library libstdc++-6.dll." with both. This was in debug, so I tried release, and I got a similar error, with some other entry point not found.
I searched the forums, and I found suggestions that I should link libstdc++ statically. I inserted -static-libgcc -static-libstdc++ at the lines QMAKE_LFLAGS = and QMAKE_LFLAGS_DEBUG = in the file c:\Qt\mkspecs\win32-g++\qmake.conf. This had no effect at all, even after restarting Qt Creator and rebuilding. If I don't copy the libstdc++-6.dll, it still requires it.
Of course, my simple test program without opencv runs from the exe without needing any libstdc++-6.dll, so that means my opencv build is responsible? I wanted to build opencv anew, but I cannot find any CMake settings referring to libstdc++ !
It might be a clue:
When using one of the libstdc++-6.dll files, the error about a missing entrypoint mentions QtGui4.dll. I have a debug build, so it should be QtGui*d*4.dll, shouldn't it? Are there different libstdc++s for debug and release? Either way, I tried to build release, but it didn't work either, same error
Is there no single person on this planet who tried using Qt with QtCreator and opencv 2.3 together on Windows xp, and succeeded? From searching all the forums and Qt archives, I could not find anyone. I'm ready to do the development in Linux, but I'll need a Windows release sooner or later anyway.
I'm trying to resist the temptation of the dark side, which whispers into my ears to forget Qt, MinGW, g++, opencv and try to hack together something in Visual Basic. Oh, the horrors!
Just FYI, I went basically through the same nightmare of combining Qt and OpenCV. This was my experience:
I downloaded the Qt SDK 4.7.4 with Qt Creator 2.4.1 and installed it, no problem.
I downloaded and installed OpenCV 2.4.2 and not knowing that it already came with MinGW...
I downloaded the MinGW compiler which of course had a different version than the one which came already with Qt
This completely messed up my CMake, even when I explicitly told CMake to use the Qt gcc.exe and g++.exe it also used some stuff from my freshly installed MinGW. Probably because I eagerly added every directory to my PATH variable. What a fool I was!
CMake was not able to generate any useful files, so I gave up and installed the OpenCV superpack, hoping this would make things easier.
6.I spent hours wondering, why Qt and OpenCV from the superpack didnt work properly together. I never quite understood. I had the same errors that other users describe here, like console programs crashing as soon as some OpenCV was included. The strange thing is, that I could start the executable manually from FileExplorer (I added all .dlls you could think of to the project folder: opencv_core242.dll, opencv_highgui242.dll, QtCore4.dll, QtGui4.dll and so on...) BUT I could not launch my little test program from within the Qt Creator environment.
I analysed if there was a problem with my DLLs using depends.exe and found out that even though I configured everything to be in DEBUG using the MinGW compiler, my program still tried to use QtCore4.dll and not QtCore4d.dll... So my best guess was, that it was mixing debug and release version.
I gave up using the superpack and again tried to use CMAKE first and then build OpenCV using the Qt MinGW version AND making sure to setup everything for Debug mode and enable the QT option. But no luck with that so far
I stopped using MinGW and switched over to MSVC2010, which works better. However I am still not able to debug the program since the MSVC2010 debugger engine seems to be missing. I dont really know how to manually add this but I am still working on it
So what I can definitely tell is that using Qt and OpenCV for somebody who has little experience is far from trivial!
You should build OpenCV from source, as you already did, it is no hassle. Note that recent versions of OpenCV can be built with and w/o Qt. Highgui optionally uses Qt! It is your choice if you build with or without Qt.
I used Qt libraries together with OpenCV for long time now. I never went for the SDK, instead I used the libs which are built for corresponding VS version. See here: http://qt.nokia.com/downloads/downloads#qt-lib
You can have it for VS2008 and VS2010, but earlier versions are also available built for VS2005. Old versions of Visual Studio suck so hard, why use them anyway.
Then I never had problems pulling it together in a CMake project. It goes along the lines of:
find_package(OpenCV)
find_package(Qt4 ${VOLE_MINIMUM_QT_VERSION} COMPONENTS QtCore QtGui)
find_package(Qt4 ${VOLE_MINIMUM_QT_VERSION} COMPONENTS QtOpenGL)
...
qt4_wrap_cpp(moc_sources ${vole_module_moc_sources})
qt4_wrap_ui(uic_sources ${vole_module_ui_sources})
qt4_add_resources(rcc_sources ${vole_module_rcc_sources})
You know, the usual stuff.
Five man weeks later you may probably get it run under Windows, while under GNU/Linux it is three commands in the shell.
You might have an easier time configuring Qt Creator with OpenCV. This post shows how to achieve that, step-by-step! It displays several screenshots to aid in the process too.