Loading

Opencv 4.3(CUDA11 ) 编译踩坑记录

前言

OpenCV接触也有六七年了,没想到还能折在这... 组内新配的服务器,打算编译cuda版本opencv,花了一天才全部搞定.....


一、 CUDA_nppicom_LIBRARY are used in this project, but they are set to NOTFOUND

解决办法

具体见上一篇文章Opencv-GPU 编译错误 CUDA_nppicom_LIBRARY (ADVANCED) 未定义

二、 nvcc fatal : Unsupported gpu architecture 'compute_86'

查询官网,3080显卡的算力是8.6,设置8.6并没有问题. 机器的CUDA是用apt命令安装的,亲测确实是这个导致。

解决办法

  1. 卸载
    执行如下命令
sudo apt-get autoremove  nvidia-cuda-toolkit nvidia*
  1. 从官网下载CUDA包,安装即可。

三、 CMake Error: Cannot determine link language for target "ade".

如图,应该是下载python-ide失败。

解决办法

这里手动到github页面(https://github.com/opencv/ade/releases)下载到本地,然后在opencv根目录/modules/gapi/cmake/DownloadADE.cmake里更改ADE_root为本地路径。具体如图:

四、 fatal error: nvcuvid.h: No such file or directory

这个头文件在cuda10 以后就被弃了,所以即使装完CUDA也缺失。

解决办法

可以从NVIDIA下载NVIDIA Video Codec SDK 获取, 然后放入系统的/usr/includes路径。具体文件如图:

五、/usr/bin/ld: cannot find -ltrue


这个问题就绝了,缺少true库,但是找了半天,并没有听说过libtrue.so这个库...
受到issusBuild opencv with cuda error : /usr/bin/ld: cannot find -ltrue #19794启发,这个问题是-D CUDA_nppicom_LIBRARY=true导致的,这个变量由于版本变动未定义,所以我们加了这一句。但是true导致在链接库时导致找不到。

解决办法

抖机灵随意找了一个系统肯定有的库stdc++,把原来的-D CUDA_nppicom_LIBRARY=true 改成-D CUDA_nppicom_LIBRARY=stdc++ 大功告成!

六、将编译的Opencv安装到Anacodna虚拟环境

在编译通过后,可以修改cmake命令,使得安装二进制文件到指定的python环境文件目录。

  1. 激活虚拟环境source activate 环境名称,主要是为了获取虚拟环境的路径,如果知道可以直接替换;
 cmake \
    -D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
    -D OPENCV_GENERATE_PKGCONFIG=ON \
    -D BUILD_opencv_python3=ON \
    -D BUILD_opencv_python2=OFF \
    -D PYTHON3_EXECUTABLE=$(which python3) \
    -D PYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
    -D PYTHON_INCLUDE_DIR2=$(python3 -c "from os.path import dirname; from distutils.sysconfig import get_config_h_filename; print(dirname(get_config_h_filename()))") \
    -D PYTHON_LIBRARY=$(python3 -c "from distutils.sysconfig import get_config_var;from os.path import dirname,join ; print(join(dirname(get_config_var('LIBPC')),get_config_var('LDLIBRARY')))") \
    -D PYTHON3_NUMPY_INCLUDE_DIRS=$(python3 -c "import numpy; print(numpy.get_include())") \
    -D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
    ..  && make install ```
posted @ 2021-07-21 18:33  Geoffrey_one  阅读(2163)  评论(0编辑  收藏  举报
/*
*/