当前位置:   article > 正文

ubuntu18.04下安装OpenCV-3.1.0的坑_the old behavior for policy cmp0026 will be remove

the old behavior for policy cmp0026 will be removed from a future version of
  1. CMake Deprecation Warning at CMakeLists.txt:72 (cmake_policy):
  2. The OLD behavior for policy CMP0022 will be removed from a future version
  3. of CMake.
  4. The cmake-policies(7) manual explains that the OLD behaviors of all
  5. policies are deprecated and that a policy should be set to OLD only under
  6. specific short-term circumstances. Projects should be ported to the NEW
  7. behavior and not rely on setting a policy to OLD.
  8. CMake Deprecation Warning at CMakeLists.txt:77 (cmake_policy):
  9. The OLD behavior for policy CMP0026 will be removed from a future version
  10. of CMake.
  11. The cmake-policies(7) manual explains that the OLD behaviors of all
  12. policies are deprecated and that a policy should be set to OLD only under
  13. specific short-term circumstances. Projects should be ported to the NEW
  14. behavior and not rely on setting a policy to OLD.
  15. CMake Deprecation Warning at CMakeLists.txt:82 (cmake_policy):
  16. The OLD behavior for policy CMP0042 will be removed from a future version
  17. of CMake.
  18. The cmake-policies(7) manual explains that the OLD behaviors of all
  19. policies are deprecated and that a policy should be set to OLD only under
  20. specific short-term circumstances. Projects should be ported to the NEW
  21. 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)。

  1. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
  2. 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函数调用的错误。暂时感觉没有什么用,直接去除,重新编译!

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

坑是一个接一个。

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

  1. [ 86%] Linking CXX executable ../../bin/opencv_test_sfm
  2. ../../lib/libopencv_sfm.so.3.1.0: undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
  3. //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> >*)'
  4. collect2: error: ld returned 1 exit status
  5. modules/sfm/CMakeFiles/opencv_test_sfm.dir/build.make:247: recipe for target 'bin/opencv_test_sfm' failed
  6. make[2]: *** [bin/opencv_test_sfm] Error 1
  7. CMakeFiles/Makefile2:12120: recipe for target 'modules/sfm/CMakeFiles/opencv_test_sfm.dir/all' failed
  8. make[1]: *** [modules/sfm/CMakeFiles/opencv_test_sfm.dir/all] Error 2
  9. Makefile:162: recipe for target 'all' failed
  10. make: *** [all] Error 2

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

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

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

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/119838?site
推荐阅读
相关标签
  

闽ICP备14008679号