ubuntu18.04下安装OpenCV-3.1.0的坑

CMake Deprecation Warning at CMakeLists.txt:72 (cmake_policy):
  The OLD behavior for policy CMP0022 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.


CMake Deprecation Warning at CMakeLists.txt:77 (cmake_policy):
  The OLD behavior for policy CMP0026 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.


CMake Deprecation Warning at CMakeLists.txt:82 (cmake_policy):
  The OLD behavior for policy CMP0042 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.

# 选择设置合适的C语言编译器

[1] #安装所需的GCC和G ++版本:

sudo apt install gcc-4.8 g++-4.8

[2] 选择 g++-4.8 和 gcc-4.8 进行编译(对应opencv-3.1.0)。

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
sudo update-alternatives --config gcc

[3] 使用cmake 或者 cmake-gui 进行配置的时候,尽量的去除不需要的项目,以降低警告和错误数量。

[4] 根据编译提示,警告和错误,修改对应的 源代码 *.cpp, *.c, *.hpp, *.h 和 CMakeLists.txt 文件。

例如:根据提示在CMakeLists.txt中增加

set(CMAKE_CXX_FLAGS "-std=c++11") # added @ 2020-02-21 by beegreen

到了快结束时,出现了有关googletest函数调用的错误。暂时感觉没有什么用,直接去除,重新编译!

[ 82%] Built target pch_Generate_opencv_test_sfm
[ 83%] Linking CXX executable ../../bin/opencv_test_sfm
../../lib/libopencv_sfm.so.3.1.0: undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
../../lib/libopencv_sfm.so.3.1.0: undefined reference to `google::SetCommandLineOption(char const*, char const*)'
collect2: error: ld returned 1 exit status
modules/sfm/CMakeFiles/opencv_test_sfm.dir/build.make:247: recipe for target 'bin/opencv_test_sfm' failed
make[2]: *** [bin/opencv_test_sfm] Error 1
CMakeFiles/Makefile2:12050: recipe for target 'modules/sfm/CMakeFiles/opencv_test_sfm.dir/all' failed
make[1]: *** [modules/sfm/CMakeFiles/opencv_test_sfm.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

坑是一个接一个。

没有办法,安装依赖 gflags 和 glog,重新编译。如果感觉有必要,请按照参考链接在opencv3中配置sfm模块,然后重新编译安装OpenCV即可。

[ 86%] Linking CXX executable ../../bin/opencv_test_sfm
../../lib/libopencv_sfm.so.3.1.0: undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
//usr/lib/x86_64-linux-gnu/libglog.so.0: undefined reference to `google::FlagRegisterer::FlagRegisterer<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(char const*, char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
collect2: error: ld returned 1 exit status
modules/sfm/CMakeFiles/opencv_test_sfm.dir/build.make:247: recipe for target 'bin/opencv_test_sfm' failed
make[2]: *** [bin/opencv_test_sfm] Error 1
CMakeFiles/Makefile2:12120: recipe for target 'modules/sfm/CMakeFiles/opencv_test_sfm.dir/all' failed
make[1]: *** [modules/sfm/CMakeFiles/opencv_test_sfm.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

猜测,应该时之前装过其他版本的OpenCV引起的。重新cmake,关闭BUILD中的TEST项,即-DBUILD_TESTS=OFF可通过。

[100%] Generating pyopencv_generated_include.h, pyopencv_generated_funcs.h, pyopencv_generated_types.h, pyopencv_generated_type_reg.h, pyopencv_generated_ns_reg.h
/usr/lib/python3.6/re.py:212: FutureWarning: split() requires a non-empty pattern match.
  return _compile(pattern, flags).split(string, maxsplit)
[100%] Building CXX object modules/stitching/CMakeFiles/opencv_perf_stitching.dir/perf/perf_stich.cpp.o
Scanning dependencies of target opencv_python3
[100%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o
In file included from /home/npuyin/Downloads/opencv-3.1.0/opencv_contrib/modules/tracking/include/opencv2/tracking/tracker.hpp:48:0,
                 from /home/npuyin/Downloads/opencv-3.1.0/opencv/build/modules/python3/pyopencv_generated_include.h:50,
                 from /home/npuyin/Downloads/opencv-3.1.0/opencv/modules/python/src2/cv2.cpp:12:
/home/npuyin/Downloads/opencv-3.1.0/opencv_contrib/modules/tracking/include/opencv2/tracking/onlineMIL.hpp:57:23: error: expected unqualified-id before ‘>’ token
 #define  sign(s)  ((s > 0 ) ? 1 : ((s<0) ? -1 : 0))
                       ^
/home/npuyin/Downloads/opencv-3.1.0/opencv_contrib/modules/tracking/include/opencv2/tracking/onlineMIL.hpp:57:23: error: expected ‘)’ before ‘>’ token
/home/npuyin/Downloads/opencv-3.1.0/opencv_contrib/modules/tracking/include/opencv2/tracking/onlineMIL.hpp:57:23: error: expected ‘)’ before ‘>’ token
modules/python3/CMakeFiles/opencv_python3.dir/build.make:286: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o' failed
make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
CMakeFiles/Makefile2:9771: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/all' failed
make[1]: *** [modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[100%] Linking CXX executable ../../bin/opencv_perf_stitching
[100%] Built target opencv_perf_stitching
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

出现了有关opencv_python3的一些错误,(其实,opencv_python2上也有,我直接把python2的模块关闭了)。

重新cmake,关闭BUILD中的python3项,即-DBUILD_PYTHON3=OFF可通过。

折腾多时的OpenCV终于在ubuntu18.04上完美安装。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值