开发者

OpenCV 2.1 with Qt Creator on Windows

开发者 https://www.devze.com 2023-01-22 08:12 出处:网络
I have OpenCV 2.1 and Qt (Creator) installed on Windows. Using the OpenCV C API I can link, build and run apps in Qt using OpenCV.

I have OpenCV 2.1 and Qt (Creator) installed on Windows.

Using the OpenCV C API I can link, build and run apps in Qt using OpenCV.

Ho开发者_如何转开发wever, the when using the OpenCV C++ API, I am getting linking problems.

This is probably due to C++ ABI problems, since I'm using the pre-built binaries (built with MSVC-2008) for Windows and Qt Creator uses MinGW.

How do I configure CMake to rebuild OpenCV 2.1 so that the resulting .libs are compatible with Qt?

Thanks!


The simplest way is to do one of these:

Option 1: You use the Qt SDK+mingw: go to the qt install directory and open a Qt command prompt. This will add you mingw toolchain to your PATH. Add the cmake binary to your PATH: (only an example, real directory might differ)

set PATH="C:\Program Files\CMake\bin;%PATH%

Option 2: You use a standalone installation of mingw: Either go to the mingw install directory and doubleclick the mingw32vars.bat or similar. A command prompt should pop up and gcc should be in PATH. If there is no such file, open a command prompt: type cmd in the windows search bar (Vista/7) or type cmd in the Run command dialog. Add mingw to PATH yourself (again, example directory, might differ on your system):

set PATH=C:\MinGW\bin;%PATH%

Common second step: Download the OpenCV sources, extract them somewhere and cd to that directory with your command prompt. Ensure all tools can be found in PATH by running these commands:

cmake --version
gcc -v

These should report some info on the programs. If one command returns "Command not found" or similar, you haven't set up your PATH correctly.

Compiling OpenCV: I understand from your question that the OpenCV library you're trying to use is built using CMake. From your command prompt (which now is set to the OpenCV source directory), do the following:

mkdir build
cd build
cmake .. -G"MinGW Makefiles"
mingw32-make

This should build the library in the "build" subdirectory. If there are any errors related to cmake or mingw32-make, that would be problems for OpenCV.


You need to make sure that CMake will find the same MinGW that was used to compile Qt. If you downloaded the QtCreator bundle, you should have a mingw directory in Qt installation directory. Make sure that this directory is in your path and that the correct version of MinGW will be used (for example using the command "which"). Another alternative is to configure the CMake variable CMAKE_CXX_COMPILER so that it points to the correct executable in the mingw directory.

After that, all you need to do is run CMake in your OpenCV folder, telling it to generated MinGW makefiles, then run make and you're done (hopefully)!


You need to use the pre-built MinGW binaries which can be found on the qt ftp site.


This post shows step by step how to install Qt on Windows and how to compile OpenCV 2.3.1 with MingW and integrate it with Qt-Creator.

It provides screenshots and videos for orientation.

0

精彩评论

暂无评论...
验证码 换一张
取 消