在Windows 7 64位上使用MinGW gcc / g ++编译openCV 2.3.1程序 [英] Compiling openCV 2.3.1 programs with MinGW gcc/g++ on Windows 7 64bit

查看:263
本文介绍了在Windows 7 64位上使用MinGW gcc / g ++编译openCV 2.3.1程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个星期,我一直在努力编译openCV程序。我试过了我可能在互联网上找到的一切。

For a week I've been struggling with compiling openCV programs. I've tried everything I could possibly find on the internet.

我所做的是:我已下载 OpenCV- 2.3.1-win-superpack.exe ,并遵循此官方安装指南

What I did is: I've downloaded OpenCV-2.3.1-win-superpack.exe and followed this official installation guide.

在CMake(gui)我的源是:D:\opencv和构建目标是:C:\opencv。

In the CMake (gui) my source was: D:\opencv and build destination was: C:\opencv.

我也添加了C:\opencv\install\bin; C:\opencv\bin到我系统的PATH变量。

I've also added C:\opencv\install\bin;C:\opencv\bin to my system's PATH variable.

我想要的是使用MinGW的gcc / g ++编译器在我的Windows操作系统上编译openCV程序。

What I want is to compile openCV programs on my Windows OS using MinGW's gcc/g++ compilers.

我已经尝试了各种gcc / g ++参数,我发现在互联网和天玩-I和-L选项,编译器永远找不到openCV功能或结构。

I've tried various gcc/g++ parameters that I've found on the internet and days playing with the -I and -L options the compiler can never find the openCV functions or structures.

我想要编译的内容:

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>

int main(int argc, char *argv[])
{
  // Nothing but create a window
  cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
  cvMoveWindow("mainWin", 100, 100);
  cvWaitKey(0);
  return 0;
}

错误:

输入

gcc test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"

输出

...\ccK4MfHv.o:test.c:(.text+0xa0b): undefined reference to `cvFree_'


b $ b

或使用g ++:

Or with g++:

输入

g++ test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"

输出

...\ccXCTKa1.o:test.c:(.text+0x1e): undefined reference to `cvNamedWindow'

注意:试图在VS2005中编译我得到相同的错误。

Side note: trying to compile in VS2005 I get the same error.

感谢您的时间!

推荐答案

如果有人需要解决这个问题,这里是我如何得到发布的OpenCV / HighGUI示例代码编译在Windows 7 x64使用MinGW,MSYS和CMake:

In case someone else needs to solve this issue, here's how I got the posted OpenCV/HighGUI sample code to compile in Windows 7 x64 using MinGW, MSYS, and CMake:


  1. 使用MinGW / MSYS / CMake从源代码构建OpenCV。这是因为我无法获得MinGW编译版本的OpenCV-win-SuperPack正确链接在MinGW / MSYS / Windows 7 x64。

  1. build OpenCV from source using MinGW/MSYS/CMake. This is because I could not get the MinGW compiled version in the OpenCV-win-SuperPack to link properly in MinGW/MSYS/Windows 7 x64.

如需完整参考,我如何编译OpenCV:

For full reference, here's how I compiled OpenCV:


  • 确保你有一个最新的CMake(v2.6或更高版本)和MinGW ,G ++和MSYS选项)

  • 如果您想要新的基于Qt的OpenCV HighGUI前端,您需要安装Qt 4(SDK)。

  • 下载OpenCV源/超级版本2.2或更高版本(我使用OpenCV-2.3.1-win-superpack.exe)

  • 将内容解压缩到[OPENCV_SOURCE_DIR]把它放在C:/ opencv,所以应该有一个文件在C:/ opencv / README例如)

  • 在其他地方创建一个[OPENCV_BUILD_DIR]目录(我使用C:/ opencv / build / mingw)

  • 使用CMake-GUI工具,将源目录指定为[OPENCV_SOURCE_DIR],将目录指定为[OPENCV_BUILD_DIR],然后单击配置。

  • 您可能希望/需要去调整选项(例如我勾选了Qt和Qt-OpenGL条目,然后再次单击配置,然后必须提供qmake可执行文件的路径)

  • 一旦你完成配置OpenCV,在MSYS终端中生成

  • ,浏览到[OPENCV_BUILD_DIR],然后运行make来生成代码(可能需要一些时间)

  • 一旦建立正确,运行make install,它将生成的代码/ libraries / include dirs收集到[OPENCV_BUILD_DIR] / install文件夹中(如果在使用CMake-GUI工具时更改了相应的选项, )

  • 将[OPENCV_BUILD_DIR] / install / bin文件夹添加到PATH环境变量。如果你不知道如何做到这一点,那么我建议使用路径编辑器GUI工具。

  • 如果你最终使用Qt,你还需要把bin文件夹Qt SDK中的PATH环境变量。这是包含qmake.exe的文件夹。

  • make sure you have an up-to-date CMake (v2.6 or later) and MinGW (with GCC, G++, and MSYS options) installed
  • if you want the new Qt-based OpenCV HighGUI front-end, you will need to install Qt 4 (SDK).
  • download a OpenCV source/superpack version 2.2 or later (I used OpenCV-2.3.1-win-superpack.exe)
  • unzip the contents to [OPENCV_SOURCE_DIR] (I put it in C:/opencv, so there should be a file at C:/opencv/README for example)
  • create a [OPENCV_BUILD_DIR] directory elsewhere (I used C:/opencv/build/mingw)
  • use the CMake-GUI tool, specify the source directory as [OPENCV_SOURCE_DIR], the build directory as [OPENCV_BUILD_DIR], and click "Configure".
  • you may wish/need to go tweak the options (e.g. I ticked "Qt" and "Qt-OpenGL" entries, then clicked "Configure" again, then had to provide the path to the qmake executable)
  • once you have finished configuring OpenCV, click "Generate"
  • in a MSYS terminal, browse to [OPENCV_BUILD_DIR], and run "make" to build the code (this may take a while)
  • once the has been built properly, run "make install", which collects the built code/libraries/include dirs into [OPENCV_BUILD_DIR]/install folder (or a different folder if you changed the corresponding option when using the CMake-GUI tool)
  • add [OPENCV_BUILD_DIR]/install/bin folder to the PATH environmental variable. If you do not know how to do this, then I'd recommend using the Path Editor GUI tool.
  • if you end up using Qt, you will also need to put the bin folder of Qt SDK in the PATH environmental variable. This is the folder that includes qmake.exe.

将以下示例代码放入名为test.c的文件。我修改了包含它们以使它们与OpenCV v2.2及更高版本兼容。

put the following sample code into a file called test.c. I modified the includes slightly to make them compatible with OpenCV v2.2 and above.

 #include <stdlib.h>
 #include <stdio.h>
 #include <math.h>
 #include <opencv/cv.h>
 #include <opencv/highgui.h>

 int main(int argc, char *argv[])
 {
   // Nothing but create a window
   cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
   cvMoveWindow("mainWin", 100, 100);
   cvWaitKey(0);
   return 0;
 } 


  • .c并运行:

  • in a MSYS terminal, browse to the folder where you put test.c, and run:

    gcc -o test -I"[OPENCV_BUILD_DIR]/install/include" test.c \
      -L"[OPENCV_BUILD_DIR]/install/lib" \
      -lopencv_core[OPENCV_VERSION] \
      -lopencv_imgproc[OPENCV_VERSION] \
      -lopencv_highgui[OPENCV_VERSION]
    

    在我的情况下:

    gcc -o test -I"/c/opencv/build/mingw/install/include" test.c \
      -L"/c/opencv/build/mingw/install/lib" \
      -lopencv_core231
      -lopencv_imgproc231
      -lopencv_highgui231
    


  • 路径编辑器: http://www.redfernplace.com/software-projects/patheditor/

    这篇关于在Windows 7 64位上使用MinGW gcc / g ++编译openCV 2.3.1程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆