ubuntu 11.04 安装opencv 2.2

来源:互联网 发布:java中log4j获取ip 编辑:程序博客网 时间:2024/06/16 01:17

1.1 错误1:undefined reference to `cvCreateCameraCapture_V4L(int)'

在 Ubuntu 11.04 下编译 OpenCV2.2,出现了如下错误:

Linking CXX static library ../../lib/libopencv_haartraining_engine.a[ 80%] Built target opencv_haartraining_engineScanning dependencies of target opencv_createsamples[ 80%] Building CXX object modules/haartraining/CMakeFiles/opencv_createsamples.dir/createsamples.oLinking CXX executable ../../bin/opencv_createsamples../../lib/libopencv_highgui.so.2.2.0: undefined reference to `cvCreateCameraCapture_V4L(int)'collect2: ld returned 1 exit statusmake[2]: *** [bin/opencv_createsamples] Error 1make[1]: *** [modules/haartraining/CMakeFiles/opencv_createsamples.dir/all] Error 2make: *** [all] Error 2

其中关键的错误提示在于:

undefined reference to `cvCreateCameraCapture_V4L(int)'

在 Ubuntu 11.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),具体的解决方法查看这里。

这两个解决办法里,我试验了第一种方法,的确是可以解决上述问题;不过我没测试第二种方法。

知其然还要知其所以然,根本的原因在于:

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 就会产生。

详细的解释可以参看 Ticket #324 和《Ubuntu11.04下安装opencv2.2编译(make)出错的原因解析及解决方法》。

1.2 错误2: linux/videodev.h: No such file or directory

我今天在 Ubuntu 11.04 上编译 OpenCV2.2,又碰到这样一个问题,在安装好 Utuntu-11.04-server 以及相应的依赖包后,再用 cmake, make 编译 OpenCV2.2 出错,提示如下错误:

/home/water/OpenCV/OpenCV-2.2.0/modules/highgui/src/cap_v4l.cpp:217:28: fatal error: linux/videodev.h: No such file or directorycompilation terminated.make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_v4l.o] Error 1make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2make: *** [all] Error 2

这个问题在 OpenCV 的讨论组里也有讨论,由于 Ubuntu11.04 版本附带的 Linux 内核已经去掉了对 libv4L 的支持,因此需要自己安装 libv4L 库的头文件,尤其是 lib4l 包,该包是用命令

$ sudo apt-get install libv4l-dev

来安装的,注意这里是 libv4L 而不是 libv41;

可是,现在你继续安装,依然会出现上述错误。这是由于这样安装的 libv4L 库把头文件名称改为

/usr/include/libv4l1-videodev.h

等。知道了原因,解决办法也很简单,只需要把出错这行代码的 #include 头文件改掉,即把文件

/modules/highgui/src/cap_v4l.cpp

第 217 行的

#include <linux/videodev.h>

代码,改为下面这行

#include <libv4l1-videodev.h>

这行代码。

这样,就可以顺利进行编译了。

1.3 OpenCV2.2 为 Ubuntu11.04 修订后的源代码

为了方便,可以使用浏忙绪绪针对 Ubuntu11.04 修改打包后的 OpenCV2.2.0 代码:

./attachments/OpenCV-2.2.0-Ubuntu11.04-WaterLin.zip


原创粉丝点击