在Ubuntu10.04上安装OpenCV3.2.0(OpenCV4.01.3.4等失败)问题及心路历程记录

在旧版Ubuntu10.04上安装OpenCV4.0.1时遇到编译错误,涉及protobuf、ADE框架和C++11支持问题。尝试通过关闭无关模块、升级GCC至4.8.0、修改源码和关闭OpenCL等方式解决,最终成功安装OpenCV3.2.0,但在虚拟机上仍存在问题。错误主要集中在protobuf、OpenCV的videoio模块与FFmpeg的兼容性上。
摘要由CSDN通过智能技术生成

因为项目的原因,需要在一个很老的机子上安装OpenCV,老机子只能装Ubuntu10.04,反正硬着头皮上吧,之前也装过好几次,因为要读取网络摄像头,OpenCV版本太低也不行,必须要3.2.0以上videocapture类中才能用网址获取视频流,所以装高版本的OpenCV,反正都会有问题,直接装最新的,just do it。

环境:Ubuntu10.04 i386版本,OpenCV 4.01,通过CMake 3.6.3编译

首先官网下载OpenCV4.01.zip,解压之后安装,按照官方的教程装的,只装了必要的依赖https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html

解压,然后执行:

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

执行make -j7就出错了,然后看网上说最好不要多线程,make clean之后直接make,出现以下错误1:

In file included from /home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/repeated_field.h:62,
                 from /home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/extension_set.h:51,
                 from /home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/extension_set.cc:38:
/home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/message_lite.h:116: error: expected ‘;’ before ‘const’
/home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/message_lite.h:120: error: expected ‘;’ before ‘T’
/home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/message_lite.h: In function ‘const std::string& google::protobuf::internal::GetEmptyStringAlreadyInited()’:
/home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/message_lite.h:139: error: ‘class google::protobuf::internal::ExplicitlyConstructed<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’ has no member named ‘get’
In file included from /home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/extension_set.h:51,
                 from /home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/extension_set.cc:38:
/home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/repeated_field.h: At global scope:
/home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/repeated_field.h:111: error: template declaration of ‘google::protobuf::RepeatedField google::protobuf::final’
/home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/repeated_field.h:112: error: expected primary-expression before ‘public’
/home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/repeated_field.h:112: error: expected ‘}’ before ‘public’
/home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/repeated_field.h:114: error: expected ‘)’ before ‘*’ token
/home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/repeated_field.h:115: error: expected unqualified-id before ‘const’
/home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/repeated_field.h:115: error: expected ‘)’ before ‘const’
/home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/repeated_field.h:117: error: expected ‘)’ before ‘begin’

。。。。

/home/opencv-4.0.1/3rdparty/protobuf/src/google/protobuf/repeated_field.h:2656: error: expected declaration before ‘}’ token
make[2]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/extension_set.cc.o] Error 1
make[1]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/all] Error 2
make: *** [all] Error 2

通过make 2> /home/build_output输出错误,一共输出400多行,感觉这一整个文件都遇到了语法错误。

首先排除源文件错误的选项,大概率源文件是不会出错的,

猜想1:C++标准的问题,OpenCV4.01是最新的,官方说在Ubuntu10.04测试通过,而且这是在编译到14%发生的错误,所以大概率不是C++标准的问题。

猜想2:include文件位置不对,之前自己写程序遇到过这种问题,系统中的include的位置不对,但是编译的时候并没有用到系统中的头文件。

猜想3:网上搜索说是protobuf版本不对,不过我反正不用这一部分,所以就重新编译cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. 加上-D BUILD_PROTOBUF=OFF -D BUILD_opencv_dnn=OFF试一试,竟然超过了14%,OK,这是编译的一小步,但这是我人生的一大步,进度条继续向前冲啊!

上面这个经历我学到了一个方法:当出错的时候,舍弃掉出错的部分,还没高兴完,到17%的时候又出错了!

错误2:In file included from /home/opencv-4.0.1/build/3rdparty/ade/ade-0.1.1d/sources/ade/include/ade/util/math.hpp:14,
                 from /home/opencv-4.0.1/build/3rdparty/ade/ade-0.1.1d/sources/ade/source/alloc.cpp:16:
/home/opencv-4.0.1/build/3rdparty/ade/ade-0.1.1d/sources/ade/include/ade/util/assert.hpp:27: error: expected unqualified-id before ‘[’ token
/home/opencv-4.0.1/build/3rdparty/ade/ade-0.1.1d/sources/ade/include/ade/util/assert.hpp:29: error: expected unqualified-id before ‘[’ token
/home/opencv-4.0.1/build/3rdparty/ade/ade-0.1.1d/sources/ade/include/ade/util/assert.hpp:86: error: expected unqualified-id before ‘[’ token
In file included from /home/opencv-4.0.1/build/3rdparty/ade/ade-0.1.1d/sources/ade/source/alloc.cpp:16:
/home/opencv-4.0.1/build/3rdparty/ade/ade-0.1.1d/sources/ade/include/ade/util

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值