linux下安装opencv(c++)的一些踩坑问题

如果预装了anaconda,在安装时,需要退出base环境,否则在make时,会报很多错误。

比如,下面这些错误,

make[2]: *** [apps/annotation/CMakeFiles/opencv_annotation.dir/build.make:89:bin/opencv_annotation] 错误 1
make[1]: *** [CMakeFiles/Makefile2:3014:apps/annotation/CMakeFiles/opencv_annotation.dir/all] 错误 2

/usr/bin/ld: /lib/x86_64-linux-gnu/libwayland-client.so.0: undefined reference to `ffi_type_uint32@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libwayland-client.so.0: undefined reference to `ffi_type_sint32@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libp11-kit.so.0: undefined reference to `ffi_closure_alloc@LIBFFI_CLOSURE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libwayland-client.so.0: undefined reference to `ffi_call@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libp11-kit.so.0: undefined reference to `ffi_type_uint8@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libp11-kit.so.0: undefined reference to `ffi_prep_closure_loc@LIBFFI_CLOSURE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libp11-kit.so.0: undefined reference to `ffi_type_uint64@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libwayland-client.so.0: undefined reference to `ffi_type_pointer@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libwayland-client.so.0: undefined reference to `ffi_type_void@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libwayland-client.so.0: undefined reference to `ffi_prep_cif@LIBFFI_BASE_7.0'
collect2: error: ld returned 1 exit status
 看上去是库的链接问题,但实际上是因为在base虚拟环境下。

在cmake过程,其实cmake文件也提示了和conda有关
-- Configuring done
CMake Warning at cmake/OpenCVUtils.cmake:1508 (add_library):
  Cannot generate a safe runtime search path for target opencv_imgcodecs
  because files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/hlg/anaconda3/lib
    runtime library [libpng16.so.16] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/hlg/anaconda3/lib
    runtime library [libtiff.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/hlg/anaconda3/lib
 

因此,在linux下安装了conda环境再安装c++的opnecv,一定要记得退出虚拟环境。

其他的安装,正常参考普通教程即可。

命令行安装教程

Ubuntu 20.04下搭建C++ & OpenCV 4.6.0 & cmake编译 - 知乎 (zhihu.com)

图形化安装过程
(238条消息) 【安装教程】Ubuntu18.04中用CMake-gui安装OpenCV4.1.0和OpenCV_contrib-4.1.0(图文)_wuyu1125的博客-CSDN博客

另外,其他过程中下载文件的问题可参考

Ubuntu16.04安装opencv4.1.2和opencv_contrib4.1.2(离线)_data: download: face_landmark_model.dat_拖杀猪刀的的博客-CSDN博客

你可能感兴趣的:(opencv,人工智能,计算机视觉)