您的位置:首页 > 运维架构

codeblocks-13.12mingw 配置opencv-3.1.0(一)

2016-01-17 21:18 459 查看

一、问题描述

由于opencv-3.1.0 只提供编译好的vc12 和vc14版本,而codeblocks默认使用的是mingw编译器并没有提供,所以如果使用vc12或vc14就会出现

Build: Debug in test (compiler: GNU GCC Compiler)===|

obj\Debug\main.o||In function `main':|

E:\OpenCv工程\test\main.cpp|5|undefinedreference to `cvLoadImage'|

E:\OpenCv工程\test\main.cpp|6|undefinedreference to `cvNamedWindow'|

E:\OpenCv工程\test\main.cpp|7|undefinedreference to `cvShowImage'|

E:\OpenCv工程\test\main.cpp|8|undefinedreference to `cvWaitKey'|

E:\OpenCv工程\test\main.cpp|9|undefinedreference to `cvReleaseImage'|

E:\OpenCv工程\test\main.cpp|10|undefinedreference to `cvDestroyWindow|

“未定义”错误

测试用例

#include "cv.h"
#include "highgui.h"
int main()
{
IplImage* img = cvLoadImage("OL.jpg",1);
cvNamedWindow( "Example1", 0 );
cvShowImage("Example1", img);
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
return 0;
}

解决办法就是用codebooks自带的编译器重新编译OpenCV 源码

在这里我们使用cmake工具生产makefile文件

二、cmake 配置

(1)选择本地编译器,以及编译器类型



(2)选择编译器所在路径,其实就是CodeBlocks 中gcc和g++的路径



(3)选择要编译源码路径,已经编译后生存文件存放路径

Where is the source code 选择OpenCV 源码解压地址 D:/OpenCV/opencv/sources

Where to build the binaries 编译后文件存放的位置 D:/OpenCV/opencv/buildCodeBlocks



(4)然后Configure



(5)完成进度条,选择Generate

此时makefile文件已经生成

三、用mingw32对其进行编译

(1)之后用mingw对其进行编译,进到刚才的保存目录,这里是D:/OpenCV/opencv/buildCodeBlocks”,输入mingw32-make;

完成后输入 mingw32-make install

ps:(我的mingw32 路径在D:\ProgramFiles (x86)\CodeBlocks\MinGW\bin 以配置在环境变量中Path中,所以能直接使用mingw32)

(2)运行完毕后便生成了的OpenCV库,进入“D:\OpenCV\opencv\buildCodeBlocks\install”可以查看

下面配置codeblocks 见codeblocks-13.12mingw
配置opencv-3.1.0(二)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: