Build OpenCV for UWP - c++

I'm currently struggling to build OpenCV for the UWP.
I already googled quite a lot and found Microsoft's OpenCV Github Repo which tecnically should do the magic. However, this repo and pretty much everything else I found in this regard are outdated (Visual Studio 2015, old OpenCV versions etc.). I need to use OpenCV 3.3 because it's a cross platform project and I don't want to recompile everything else solely because of an outdated git repo.
Can anyone explain the process of building OpenCV using CMake from the official repo for the UWP?
My first attempt was to simply use the Windows Dlls, however my application than shouts "Failed to load module" at me. Then, I tried to build OpenCV the Visual Studio Project files as stated here and here. However, this doesn't do it for me as it throws the following error:
CMake Error at cmake/OpenCVUtils.cmake:440 (if):
if given arguments:
"(" "OR" "OFF" ")"
Unknown arguments specified
Call Stack (most recent call first):
CMakeLists.txt:317 (OCV_OPTION)
It also tells me to check the CMakeOutput.log but there it's 0 errors everywhere.
If someone could tell me either how to get rid of this error or what to change in the CMake GUI to build OpenCV for UWP, that'd be great!
Edit:
I also tried to compile OpenCV with a platform specific toolchain for WinRT as found in platforms/winrt. It doesn't really change anything though (I'm not even sure if it should), I still get "Unable to load Dll: The specified module could not be found". Maybe GPPK is right in his assumption that it's more an UWP problem than an OpenCV one. Anyways, if anyone knows anything about this, I'd really love to get some help!

Ok, I didn't get an answer yet, so I managed to do it myself (more or less).
Here's how I did it:
Prerequisites
Visual Studio (2017)
UWP SDK
CMake
OpenCV from official repo
Steps
Create a build folder which you want the UWP libraries to built in.
Start PowerShell in this folder and execute the following command (exchange C:\OpenCV with your local OpenCV path): cmake -G "Visual Studio 15 2017" -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERS
ION="10.0" -DCMAKE_VS_EFFECTIVE_PLATFORMS=x86 -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF C:\OpenCV
If you get the same error message as I did (see question for more details), go to the root CMakeLists.txt in the OpenCV folder and add a # in front of line 317 (OCV_OPTION(ENABLE_PYLINT)). This should fix it, to check, execute the command from above once more.
Ensure that the output claims "Windows RT support YES" and "Building for Microsoft platform: Windows".
Open OpenCV.sln in the build folder. Ensure that all projects are either of type "Windows Store" or "Universal Windows" and build the ALL_BUILD Project twice: Once in Release configuration, and once in Debug. Then build the INSTALL Project.
That's it, you should find the built Dlls in the install folder. Step 3 is probably a bug in OpenCV and will hopefully be fixed in upcoming versions.

Related

How do I build Qt 3.X.X on Windows?

I downloaded a project that depends on Qt 3.X.X (legacy version). I downloaded this version from the Qt downloads archive and set the environment variables according to what the documentation tells me. I can't build the program though. The errors I get are all along the lines of
Moc'ing SomeFile.h ...
The system cannot find the path specified.
Looking into the Qt /lib folder, there's just one README file that says
If this directory is empty, you forgot to build the Qt library
I'm assuming this is the reason I can't build my project, so I would like to know how to build this Qt version. The documentation is extremely limited since it's an old version, so I can't get it to work based on that.
Some system info:
Windows 10
x64
Visual Studio 2015 installed
If you need more info, please let me know!

Cmake error libwww when compiling Ryzom

I get these errors when I try to configure in cmake:
Could NOT find Libwww (missing: LIBWWW_LIBRARIES LIBWWW_INCLUDE_DIR)
but I couldn't find any answer in google, I tried to download "w3-libwww" but I don't know how to include it on project.
I'm following this tutorial:
https://ryzomcore.atlassian.net/wiki/display/RC/Build+Source+on+Windows
I downloaded and installed all SDK and pre-requisites and I try to generate for Visual Studio C++ 10 (2010)
Please use either develop or compatibility-develop branch, the default branch has not been updated for a while and we removed dependency on libwww since :)

installing OpenCV with Code::Blocks / CMake

I am fairly new to C++ in general (though I am getting used to the basics), but now I am trying to add OpenCV to my projects to access some of the basic image processing features. I have read the documentation so I have a pretty good idea where to start, but I am really stuck with the installation.
I am working with Code::Blocks 16.01, and I have downloaded both CMake 3.4.3 and OpenCV 3.0.0 and 3.1.0. OpenCV has been extracted to "c:\opencv", and I have attempted to finish the build with CMake (using the directions from the OpenCV documentation as well as from several older posts from this site). I am selecting "Codeblocks - MinGW Makefiles" from the list of generators, though I have selected from all of the "Codeblocks" options at one point or another.
Anyway, whenever I try to configure or generate I receive the following error: "The program can't start because libintl-8.dll is missing from your computer." So yeah, I am stuck.
It is worth noting that many, if not all, of the posts I have found refer to a directory named "\x86\mingw\lib", however I cannot find "mingw" in any of the OpenCV downloads (and the most recent is missing "x86" as well) - so none of these posts have been particularly useful to me (for example):
How to compile a program using OpenCV 2.4.3 with Code::Blocks?
Put the path to all the MinGW dll files in your pc's path variable. Check your Code::Blocks installation directory ( C:\Program Files (x86)\CodeBlocks\MinGW\bin ) if it does not exist, you'd have to download and install MinGW separately. You'd have to add the MinGW .dll files to the path environment.

Building Qt5 with Visual Studio 2012 / Visual Studio 2013, and integrating with the IDE

How do you get Qt5 to download and integrate with Visual Studio 2012? What are some of the problems you will encounter, and how do you solve those problems?
UPDATE re. Visual Studio 2013
Successes are reported with Visual Studio 2013 as well, and the notes are being maintained for VS 2013.
Also note that the focus of the question is strongly on just building Qt with Visual Studio. There are also notes about integrating with the Visual Studio IDE
This method is tested to work on Visual Studio 2013. Pre-built binaries using Visual Studio 2012 and 2013 are available here, including OpenGL versions.
Step 1: The Setup
Download and install RapidEE here. RapidEE is a windows environment variables editor. It is extremely useful for the rest of this process (and just in general).
Install the DirectX 11 SDK. It is now part of the Windows 8 SDK, so you first have to install the DirectX 10 SDK, which you can get here (but see warning in next sentence). If you have the Visual C++ 2010 Redistributable Package installed, and you probably do (it is automatically installed along with VS 2010), follow the steps outlined here to assist with the DirectX 10 installation. Once you have the DirectX 10 SDK installed, download and install the Windows 8 SDK here, which contains the DirectX 11 SDK. Yes, this is a pain, but unless you know you have the DirectX 11 SDK, the Qt build will fail.
Install Python for Windows (I've heard 2.6+, working with 3.3) from Python.org or Anaconda Python.
Install Perl for Windows from ActiveState.
Step 2: Gitting (and building) Qt5 (yes, that means Git)
Follow the installation guide for Windows at the qt-project website.
Summary
To summarize the details from the above link and from the following notes (PLEASE SEE FOLLOWING NOTES if you have any errors; they might be answered):
Uninstall Avast (if you have this installed) to avoid build errors. Yes, that literally means uninstall it. Remove it 100% from your system. Deactivating it will not work. See detailed notes below.
Note for the first steps: DO NOT use SmartGit for the first git pull, below (unless you really know what you're doing), as SmartGit's defaults will pull everything, and that's not what you want.
Git for Windows must be installed.
Decide where you want to put the Qt installation, and cd to the directory that will contain the new installation from any Command Prompt window. (Because the process is so fragile and error-prone, I personally put it directly in C:, but this is likely not necessary).
From the above directory, execute:
git clone git://gitorious.org/qt/qt5.git qt5
This is fast. Once complete, you should be on the 'stable' branch, but you can always run git checkout stable after cding into the newly-created qt5 directory, just to be sure. Using git checkout 5.4.1 is confirmed to work with VS2013 64-bit.
Close out of your current command prompt window (if it's not a Visual Studio command prompt window) before proceeding to the next step. This is to make sure you're using the Visual Studio command prompt window in the next steps.
Next run the 32-bit (x86) or 64-bit VS Tools command prompt (depending on whether you're building Qt5 as 32- or 64-bit). To access this, you must find it through the Start menu - go to Program Files -> [Microsoft] Visual Studio 2012/2013 -> Visual Studio Tools, and you'll see it in there with a funny name; the name should include the phrase Native Tools; the 32-bit version will have x86 in the name and the 64-bit version will have x64 in the name.
cd into the newly-created qt5 directory from the step above.
From within the Visual Studio command prompt, the remainder of the Qt submodules must be downloaded:
perl ./init-repository --no-webkit
It takes kind of a while to execute this step, because it has to download a lot, but it's not too terrible on a decent connection.
Then download any remaining OPTIONAL submodules that init-repository does not download - SmartGit works well only starting at this stage (see comments below).
Once the download of Qt is complete, the following command prepares the build environment (it should also be executed using the [32|64] VS Native Tools Command Prompt):
configure -developer-build -opensource -confirm-license -mp -nomake examples -nomake tests -debug-and-release -c++11 -no-warnings-are-errors -platform win32-msvc2012.
Notes on this command line: the c++11 option might not be necessary with the VS2012 compiler, but works with VS2013; the -no-warnings-are-errors is necessary in case you get errors on a 64-bit automatic build of ANGLE; -platform is automatically set to win32-msvc2012, so by default the 32-bit build of Qt is used, and -platform probably does not need to be supplied at the command line (EVEN if you have previous versions of VS installed). For VS2013, use -platform win32-msvc2013.
It takes a few minutes to execute this step, but it's not so bad.
Finally, the command to actually build Qt on the system (also run within the VS Native Tools Command Prompt) is simply:
nmake
Expect to wait hours for the build to complete. If you specified an output folder with -prefix (see notes below), then use nmake install, otherwise that's it.
NOTES:
General Notes
In case you're confused from the above-linked documentation, just an FYI that the ANGLE library will be used (by default) instead of OpenGL, and that's why you had to install DirectX 11, above.
Make sure that you use the VS Native Tools Command Prompt to run all commands from the above link (that is, perl .\init-repository --no-webkit, configure, and nmake). You will use the [32|64] bit command prompt (x86 or x64), depending on whether you are building Qt as 32-bit or 64-bit. If you install perl with the Command Prompt open (make sure it is in the PATH), you will need to restart the Command Prompt for perl to be recognized as a command.
When running "init-repository" (from the steps in the above link), it's not clear from the documentation, but you must execute this via perl; i.e. perl ./init-repository --no-webkit. The configure and nmake commands, however, are called directly.
One very useful option to pass to configure is -mp, which causes Qt to build on multiple cores in parallel, significantly speeding up the (long) build time.
To specify an output folder add the -prefix [outfolder] to the configure command. For example, use -prefix %CD%\output\x64\vc12 would be a suitable output (sub)folder for a 64-bit Visual Studio 2013 (12.0) build.
Unicode Support (ICU)
If you want Unicode support (via ICU), pay special attention to the instructions noted within the link above. In summary, ICU must be built from scratch in VS 2012, as the only prebuilt ICU binaries for Windows are for VS 2010. Building in VS 2012 is painless - simply locate the ICU solution (.sln) in <icuroot>\icu\source\allinone, and build in both Debug and Release mode (either in 32-bit or 64-bit mode, depending on which mode you're building Qt in - DO NOT build in the other bitness, because ICU will overwrite the output folder with the binaries). (The Qt build process will properly locate the debug vs. release build of ICU.) It should build without errors. Then, add the path to <icuroot>\lib as a string entry in a (probably) NEW Windows environment variable called "LIB" (you can use Rapid EE for this; make LIB an "expandable string" in RapidEE even though there's only 1 entry), and also add the path to <icuroot>\include as a string entry in a (probably) NEW Windows environment variable called "INCLUDE". (Note: Adding these paths to the PATH variable will not work.) After Qt is built, you can remove all of these entries you've just added. Also, do add the runtime path to the ICU dll's (<icuroot>\bin) to the environment's PATH variable, or the Qt build process (specifically, when uic.exe runs) will give a deceptive and misleading error. Finally, on the configure command line (below), be sure to add -icu as an additional command-line parameter.
ICU Failure:
Currently, there seems to be a bug building Qt5 with the VS2012 compiler WHEN ICU IS ENABLED. Specifically, qtbase\src\corelib\codecs\qtextcodec.cpp Line 688 (Qt5 v5.02) fails to return a codec for codec name "US-ASCII" (the codec is NULL), causing "lrelease.exe" to crash when trying to dereference the codec later (I have lost track of that file/line number, but it is an obvious dereference of the NULL codec variable). Unfortunately, this means that to my knowledge, WebKit cannot be built with (at least the) 32-bit build of Qt5 with the VS2012 compiler, because WebKit requires ICU.
If anyone is able to build Qt5 with the VS2012 compiler with ICU enabled, please update this Wiki saying so.
ICU Clarification:
If you have ICU in your path, Qt will automatically built it. In other words, the flag "-icu" is there implicitly. However, this causes an error with "lrelease.exe" as mentioned above. So the way around this would be to add the flag, -no-icu to the configure command
Additional Submodules
If you want submodules in addition to the default submodules, you can use SmartGit (or command line) after you complete the init-repository command. SmartGit is perhaps easiest, because you do not need to copy the path to the command line, but can use the user interface directly.
WARNING: DO NOT DOWNLOAD THE OPTIONAL qlalr SUBMODULE, as it will not build in combination with the overall Qt build, and is not necessary for users of Qt, but is only used for internal Qt development.
WARNING: A shell command line, followed by perl .\init-repository --no-webkit, must be used (NOT SmartGit); these steps will properly only download the default Qt submodules. You must not use SmartGit to clone and download the Git files from git://gitorious.org/qt/qt5.git because SmartGit does not currently handle the submodules properly. Instead, open a standard Windows shell command prompt (using any command-prompt application, not necessarily the VS Tools command prompt), and (assuming Git is properly installed on the system; a SmartGit installation might or might not do this automatically; if it does not, go to Git for Windows and install directly) type git clone git://gitorious.org/qt/qt5.git directly from the command line; perhaps follow that with git checkout stable (I'm not sure if this branch is checked out by default); then follow that with the command line perl .\init-repository --no-webkit to pull down the DEFAULT repositories (except WebKit, which requires ICU and ICU seemingly cannot be built in 32-bit Qt5 with VS2012; see comments).
The steps for downloading all necessary Qt source files therefore are:
1. Use a Windows command line to execute the initial git clone git://gitorious.org/qt/qt5.git;
2. Execute perl .\init-repository --no-webkit from within a VS Tools 2012 Command Prompt; and then optionally
3. Use SmartGit (from above link) (or equivalent) to "open an existing project" (choose the Qt5 root folder) and do a Pull from within SmartGit to download any non-default repositories (but do not download qlalr). That's it; you have all necessary and optional Qt files (including submodules) on your system.
If anybody discovers other optional submodules that fail to build and/or are for internal use only (besides qlalr), please update this Wiki to specify them.
In general, the default submodules obtained via perl .\init-repository --no-webkit are sufficient. If you know, or later find out, that you other (non-default) modules, you can always add them later.
General Problems
If at some point you get the error saying that the command "python" (or anything similar) is not recognized, just check that the folder containing python.exe (or the appropriate .exe) is part of the path variable. If it is not, add it (use RapidEE as noted above for convenience) and try what you were doing again. If it is there, make sure you have restarted your command prompt AFTER the addition of the command to the path.
Two other path-related issues are important to note (quoted from the documentation associated with the link above): "Make sure the perl executable is found in the path before the perl executable provided by msysgit, since the latter is outdated"; and "You might not be able to build if sh.exe is in your PATH (for example due to a git or msys installation). Such an error is indicated by qt5-srcqtbasebinqmake.exe: command not found and alike. In this case, make sure that sh.exe is not in your path. You will have to re-configure if your installation is already configured."
During the process, you may encounter an error using nmake on a file. If you do, just go into that directory and force build the problem file. Then begin the nmake process on Qt5 again.
Specific Problems
WARNING: You may need to disable antivirus software AND SANDBOXING during the Qt nmake process (and, to be safe, throughout this entire process). Internally, Qt executes a number of executables that antivirus programs can interfere with (sometimes silently). In particular, if you have any sandboxing software, be SURE to disable sandboxing.
WARNING: AVAST! Sandbox users: Avast Sandbox has a bug in which even when you disable Avast's auto-sandbox, the sandbox will NOT turn off and it will silently sandbox all resource files automatically created by Qt's rcc program during Qt's build process. The Qt build ALWAYS fails for any user who has installed the Avast autosandbox feature, EVEN WITH AUTO-SANDBOXING TURNED OFF. THE ONLY WAY TO OVERCOME THIS ISSUE IS TO COMPLETELY UNINSTALL AVAST! FROM YOUR SYSTEM before building Qt. You can reinstall Avast! after the Qt build is complete.
The compilation of Qt5 can take a long time (hours, even with the -mp multithreading option). Patience.
Step 3: Integrating Qt5 with Visual Studio 2012
Download and install the Visual Studio Qt5 addin. It is in the "Other Downloads" section near the bottom of the page, and will not work with Visual Studio Express.
Open Visual Studio 2012, and go to Qt Options (It's under "Qt5" on the top menu bar).
In the Qt Versions tab, check to see if Qt5 is already there. If it is not, click add, choose a version name (probably a name such as 5.x.x), and navigate to the folder containing qmake.exe (usually C:\Qt\qt5\qtbase).
Exit the Qt Options dialog.
Create a new Visual Studio Project. When you see the New Project dialog, you should see the Qt5 Projects Template option.
Once you have your new Qt Project, right click on it and select "Convert to QMake generated project". Build the project, then right click on it again and select "Convert project to Qt Add-in project". Build again, then run. You should now have a working Qt Project.
Add Qt5 to an existing Visual Studio 2012 VC++ project
This section may or may not work for you. If you run into problems or have additional/better solutions, please leave a comment or edit the appropriate step.
Right-click on your project in VS, and choose "unload project". Right click on the project again, and select "edit [project name].vcxproj". This opens the project file so you can add Qt5 to it.
Go down to the Global PropertyGroup, and add or change the <Keyword> to Qt4VSv1.0.
Reload the project, then right-click and select "Convert project to Qt Add-in project"
Wait for the conversion to finish (it does not take more than a couple seconds), then choose Qt5>Project Settings. Go to the Modules tab, and check the modules you would like your project to rely on (the basic ones are Core, Widgets, and GUI).
Following the steps here, add the directory $(QTDIR)\include.
NOTES:
If at any time you are including windows.h, you need to #define NOMINMAX before doing so to prevent conflict with qdatetime.h.
Once the above steps are done, you can make your project usable by Qt Creator by selecting Qt5>Create basic .pro file.
ENDING NOTES: If you have a question related to the information contained in this guide, please post it as a new question (not an answer here), and the answer or a link to the answer may get added.
I successfully managed to integrate Qt 5.0.2 with Visual Studio 2012 on Windows 7 based on the excellent wiki above and on this qt-project link as well. Since I made some of the steps on a slightly different way, I thought it would be valid to post it in here:
The sequence below should be executed in the exact given order:
0 - Uninstall Avast (if you have this installed) to avoid build errors. Due to an Avast bug, deactivating it will not work;
1 - Install Git (>= 1.6.x);
2 - Install Python (>=2.6.x). [python.org];
3 - Install Perl (>=5.14). [activestate.com];
4 - Install Ruby. [rubyinstaller.org];
5 - Open the Windows 7 Command Prompt (don't use VS2012 Developer Command Prompt by now);
6 - Choose any directory you want for qt5, regarding that NO SPACES ARE ALLOWED for the chosen path. I decided to use the path "C:\qt5";
7 - Back to Windows 7 Command Prompt (in my case, prompting "C:\qt5>") type:
git clone git://gitorious.org/qt/qt5.git qt5
8 - Checkout the stable version:
cd qt5
git checkout stable
9 - You'll probably receive a message confirming that this version is already stable. Close the Command Prompt;
10 - Open Visual Studio's Developers Console (All Programs > Visual Studio 2012 > Visual Studio Tools > Developer Command Prompt for VS2012) and change the current directory to the one you have chosen("C:\qt5" in my example);
11 - Download Qt submodules, ignoring webkit (common source of build errors...):
perl .\init-repository --no-webkit
12 - Now enter this huge command to configure your build properly:
configure -developer-build -opensource -nomake examples -nomake tests -nomake demos -debug-and-release -c++11 -mp -nomake webkit -confirm-license
13 - Next, ensure that the module qlalr will NOT be built. To do this, open Windows Explorer and navigate to your chosen Qt directory ("C:\qt5" in my example) and check if the folder qlalr exists. If so, delete it;
14 - Time to build... Possible build errors would come from secondary modules (such as webkit), which don't affect the main Qt functionality (webkit itself should not be a problem since we've previously set the configuration not to build it). We can then ignore them and also keep the build running on independent modules:
nmake /I /K
15 - To conclude integration, follow the step 3 of the community wiki above("Step 3: Integrating Qt5 with Visual Studio 2012").
Just want to mention that there is a prebuilt version of Qt 5.2 for Visual Studio 2012 available at http://qt-project.org/downloads. So if you don't have a special interest in building Qt 5 from sources you can use the prebuild binaries, too.
There are also several precompiled (x64) binaries for different compiler versions available at the Tver-Soft website.
I was finally able to compile QT 5.1 (git) with QWebKit on Windows 8 x64 using Visual Studio 2012 and figured I'd share my experience with those that had problems as well.
Did step 1 and 2 as stated in the above post. I tried to do step 3 but SmartGit pulled a bunch of extra projects that wouldn't compile with Qt5. I was able to solve most of the problems by cloning from a different fork (e.g. https://qt.gitorious.org/qt/qt3d/), but this became too tedious to do for every extra module, so I decided against compiling any of them.
The post at ICU support in a 32-bit build of Qt5 with the VS2012 compiler causes Qt5 build failure; Webkit is also therefore unbuildable told me how to fix the ICU problem.
Download the source code at http://download.icu-project.org/files/icu4c/51.2/icu4c-51_2-src.zip and add the line
#define U_CHARSET_IS_UTF8 1
to the file %ICU%\source\common\unicode\platform.h , where %ICU% is the path to the ICU source code.
Open %ICU%\source\allinone\allinone.sln file in Visual Studio 2012 and compile. Add %ICU%\bin to your path
set PATH=%ICU%\bin64;%PATH%
Then I ran the following command in the QT root directory
configure -platform win32-msvc2012 -opengl desktop -opensource -debug-and-release -I %ICU%\include -L %ICU%\icu\lib64 -mp -qt-freetype -icu
At this point I started to suspect that no one tried to do what I was doing, because nmake started to complain about unexpected lines in the makefiles (all of which had the extension DerivedSources, e.g. Makefile.JavaScriptCore.DerivedSources and Makefile.WebCore.DerivedSources))
(set PATH=<stuff>;%PATH%) && ....
do the set PATH manually before running nmake and delete the characters up to and including && e.g.
(set PATH=<stuff>;%PATH%) && perl -ne "print $1" css\CSSPropertyNames.in ...
Becomes
perl -ne "print $1" css\CSSPropertyNames.in ...
Finally, one of these files will try to call win_flex.exe (or win-flex.exe) instead of flex. I changed it to flex.exe and everything finally compiled (Had to change it twice, because I think the file got regenerated).
Brief experience with a program that uses QWebKit and linked against this build leads me to believe everything is fine.
--Update--
Just to be complete. According to What does (set PATH=...;%PATH:)=^)%) mean in a Windows shell script, and how can I overcome failure of this line in the context of a Qt5 nmake build? (which points to http://qt-project.org/forums/viewthread/20605) most of the Makefile problems should be solvable by using jsom instead of nmake (although I still wonder about win-flex.exe)
compile Qt 5.5 with visual studio 2015:
1- Modify configure.bat in qtbase directory so it can generate configure.exe (just the first 18 lines)
#echo off
set QTSRC=%~dp0
set QTDIR=%CD%
rem if not exist %QTSRC%.gitignore goto sconf
echo Please wait while bootstrapping configure ...
for %%C in (cl.exe icl.exe g++.exe perl.exe) do set %%C=%%~$PATH:C
rem if "%perl.exe%" == "" (
rem echo Perl not found in PATH. Aborting. >&2
rem exit /b 1
rem )
if not exist mkspecs (
md mkspecs
if errorlevel 1 goto exit
)
rem perl %QTSRC%bin\syncqt.pl -minimal -module QtCore -outdir "%QTDIR%" %QTSRC%
rem if errorlevel 1 goto exit
2- configure -opensource -confirm-license -mp -nomake examples -nomake tests -release -c++11 -no-warnings-are-errors -platform win32-msvc2015 -no-ltcg
3- nmake

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.