ununtu11.04下安装opencv2.2编译(make)出错的原因解析及解决方法


0.关键字:ununtu11.04 、opencv2.2 undefined reference to `cvCreateCameraCapture_V4L(int)'

1.错误再现,原因何在??

ununtu11.04下安装opencv2.2的时候,安装到80%左右的时候,会报错。如下图所示,

ununtu11.04下安装opencv2.2编译(make)出错的原因解析及解决方法_第1张图片

图1 错误再现

google一下    undefined reference to `cvCreateCameraCapture_V4L(int)'  ,结果在这里。


其中一个,具体的解析是,网址

In some linux distros where V4L2 is enabled, CMake does not define the HAVE_CAMV4L macro, but the macro HAVE_CAMV4L2 is defined.
When the highgui.so is building and linked with an other program, a Link error undefined reference to cvCreateCameraCapture_V4L is detected, and the library is not finished. The compilation terminated at [ 83%] Building. 

翻译:在某些linux发行版本中启用了V4L2,CMake并没有定义 HAVE_CAMV4L这个宏定义,但是定义了 HAVE_CAMV4L2这个宏定义。

当编译highgui.so并需要和其他程序链接时,一个错误undefined reference to cvCreateCameraCapture_V4L 就会产生。


解决方法:

在ubuntu11.04下,可以有两种方法,(1)make ubuntu 11.04 compile with libv4l,出处。(2)fixed "undefined cvCreateCameraCapture_V4L" linker errors on some linux distros (thanks to miguelinux for the patch),网址。

修改的都是源代码,修改完毕以后再重新cmake,make,就不会报错了。


提醒:推荐使用(1)中的方法。如果以上两篇文章的英语看不懂,又或者看了也等于没看,那还是看看下面的截图。看懂了那就赶紧逃离这里,(*^__^*) 。


2.超级罗嗦的解析


(1)make ubuntu 11.04 compile with libv4l,出处。

这种方法就是作者使用的方法,大家看去吧,不懂的参考下面方法(2)的解析。


(2)fixed "undefined cvCreateCameraCapture_V4L" linker errors on some linux distros (thanks to miguelinux for the patch),网址。


下载的源代码里面找到OpenCV-2.2.0/modules/highgui/src/cap_v4l.cpp
old new  
214 214 #include <sys/types.h> 
215 215 #include <sys/mman.h> 
216 216  
  217 #ifdef HAVE_CAMV4L //我们自己加上去
217 218 #include <linux/videodev.h> 
  219 #endif //我们自己加上去
218 220  
219 221 #include <string.h> 
220 222 #include <stdlib.h> 

下载的源代码里面找到OpenCV-2.2.0/modules/highgui/src/cap.cpp
old new  
171 171             if (capture) 
172 172                 return capture; 
173 173         #endif 
174           //把本行后面的删掉,就变成本行下面的一行#if defined (HAVE_CAMV4L) || defined (HAVE_CAMV4L2) 
  174         #if defined (HAVE_CAMV4L) 
175 175             capture = cvCreateCameraCapture_V4L (index); 
176 176             if (capture) 
177 177                 return capture; 
实际上就是修改第174行。


欢迎拍砖……



你可能感兴趣的:(ununtu11.04下安装opencv2.2编译(make)出错的原因解析及解决方法)