在c ++中编译opencv [英] compiling opencv in c++
问题描述
我有一个只导入的文件:
i have a file with only import:
#include <iostream>
#include <stdio.h>
#include "cxcore.hpp"
#include "highgui.hpp"
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
}
我尝试使用g ++ -I / usr / include / opencv -lopencv -lm m.cpp
and i try to compile with g++ -I/usr/include/opencv -lopencv -lm m.cpp
get whit错误:
but get whit error:
在/usr/include/opencv/cxcore.hpp:46,
从m中包含的文件中。 cpp:5:
/usr/include/opencv/cxmisc.h:214:错误:在'void'之前的构造函数,析构函数或类型转换
/usr/include/opencv/cxmisc.h: 220:错误:'int'之前的构造函数,析构函数或类型转换
/usr/include/opencv/cxmisc.h:226:错误:'CV_INLINE'未命名类型
/ usr / include / opencv / cxmisc.h:516:错误:'CV_DEPTH_MAX'未在此范围中声明
/usr/include/opencv/cxmisc.h:522:错误:'CV_DEPTH_MAX'未在此范围中声明
/usr/include/opencv/cxmisc.h:522:错误:'CV_CN_MAX'未在此范围中声明
在包含在m.cpp:5中的文件中:
/ usr / include / opencv / cxcore.hpp:70:error:模板声明'cv :: CV_EXPORTS cv :: Size_'
/usr/include/opencv/cxcore.hpp:71:error:模板声明'cv :: CV_EXPORTS cv :: Point_'
/usr/include/opencv/cxcore.hpp:72:error:模板声明'cv :: CV_EXPORTS cv :: Rect_'
/ usr / include / opencv / cxcore。 hpp:77:错误:'fromUtf16'之前的预期初始化程序
/usr/include/opencv/cxcore.hpp:78:错误:'toUtf16'
/ usr / include / opencv / cxcore之前的预期初始化程序。 hpp:80:error:'format'之前的预期初始化程序
/usr/include/opencv/cxcore.hpp:82:错误:期望的初始化程序':'token
m.cpp:38:错误:预期'}'在输入结束
In file included from /usr/include/opencv/cxcore.hpp:46, from m.cpp:5: /usr/include/opencv/cxmisc.h:214: error: expected constructor, destructor, or type conversion before ‘void’ /usr/include/opencv/cxmisc.h:220: error: expected constructor, destructor, or type conversion before ‘int’ /usr/include/opencv/cxmisc.h:226: error: ‘CV_INLINE’ does not name a type /usr/include/opencv/cxmisc.h:516: error: ‘CV_DEPTH_MAX’ was not declared in this scope /usr/include/opencv/cxmisc.h:522: error: ‘CV_DEPTH_MAX’ was not declared in this scope /usr/include/opencv/cxmisc.h:522: error: ‘CV_CN_MAX’ was not declared in this scope In file included from m.cpp:5: /usr/include/opencv/cxcore.hpp:70: error: template declaration of ‘cv::CV_EXPORTS cv::Size_’ /usr/include/opencv/cxcore.hpp:71: error: template declaration of ‘cv::CV_EXPORTS cv::Point_’ /usr/include/opencv/cxcore.hpp:72: error: template declaration of ‘cv::CV_EXPORTS cv::Rect_’ /usr/include/opencv/cxcore.hpp:77: error: expected initializer before ‘fromUtf16’ /usr/include/opencv/cxcore.hpp:78: error: expected initializer before ‘toUtf16’ /usr/include/opencv/cxcore.hpp:80: error: expected initializer before ‘format’ /usr/include/opencv/cxcore.hpp:82: error: expected initializer before ‘:’ token m.cpp:38: error: expected ‘}’ at end of input
这是我的copencv lib内容:
this is my copencv lib content:
alberto@zefiro:~$ ls /usr/include/opencv/
cvaux.h cvcompat.h cv.hpp cvtypes.h cvvidsurv.hpp cxcore.h cxerror.h cxmat.hpp cxoperations.hpp highgui.h ml.h
cvaux.hpp cv.h cvinternal.h cvver.h cvwimage.h cxcore.hpp cxflann.h cxmisc.h cxtypes.h highgui.hpp
我在ubuntu 10.10
i'm on ubuntu 10.10
推荐答案
您需要正确加入标头 -I
(资本i)和库 -l </ code> (小写L)。
You need to properly include the headers -I
(capital i) and libraries -l
(lowercase L).
在最新的OpenCV版本上,您应该:
On the newest OpenCV versions you should do:
#include <cv.h>
#include <highgui.h>
然后尝试编译:
g++ m.cpp -o app `pkg-config --cflags --libs opencv`
注意:如果在命令行中只执行 pkg-config --cflags --libs opencv
,您将看到路径和库需要包含在g ++命令行中。
Note: if you execute only pkg-config --cflags --libs opencv
in the command line you will see the paths and libraries you need to include in the g++ command line.
这篇关于在c ++中编译opencv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!