Loading

Opencv-GPU 编译错误 CUDA_nppicom_LIBRARY (ADVANCED) 未定义

问题出现描述

  • Opencv : 4.3
  • CUDA: 11.1
  • Ubuntu 18.04

编译支持CUDA的OpenCV, CMake命令和报错内容如下:

cmake \
-D INCLUDE_DIRS=${OPENCV_INCLUDE_DIR_ANACONDA} $INCLUDE_DIRS \
-D LIBRARY_DIRS=$OPENCV_LIBRARY_ANACONDA $LIBRARY_DIRS \
-D BUILD_PYTHON_SUPPORT=ON \
-D BUILD_DOCS=ON \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-D CMAKE_INSTALL_PREFIX=/usr/local/opencv \
-D OPENCV_EXTRA_MODULES_PATH=/home/timber/Library/opencv_contrib/modules \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_python2=OFF \
-D PYTHON3_EXECUTABLE=${OPENCV_PYTHON_EXECUTABLE_ANACONDA} \
-D PYTHON3_INCLUDE_DIR=${OPENCV_INCLUDE_DIR_ANACONDA} \
-D PYTHON3_PACKAGES_PATH=${OPENCV_PACKAGE_ANACONDA} \
-D BUILD_EXAMPLES=OFF \
-D WITH_GTK=ON \
-D WITH_GTK_2_X=ON \
-D WITH_IPP=ON \
-D BUILD_TIFF=ON \
-D BUILD_opencv_cvv=OFF \
-D INSTALL_CREATE_DISTRIB=ON \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D WITH_TBB=ON \
-D WITH_QT=ON \
-D WITH_OPENGL=ON \
-D WITH_CUDA=ON \
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
-D CMAKE_LIBRARY_PATH=/usr/local/cuda/lib64/stubs \
-D CUDA_ARCH_BIN="8.6" \
-D CUDA_ARCH_PTX="" \
-D WITH_CUBLAS=ON \
-D WITH_NVCUVID=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
-D CMAKE_BUILD_TYPE=Release \
..

其中一些变量是python是虚拟环境相关的,在激活虚拟环境后运行如下命令获得,编译时取消激活防止库冲突。

OPENCV_PYTHON_EXECUTABLE_ANACONDA=$(which python${PYTHON_VERSION}) && \
OPENCV_INSTALL_PATH=$(python -c "import sys; print(sys.prefix)") && \
OPENCV_INCLUDE_DIR_ANACONDA=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") && \
OPENCV_PACKAGE_ANACONDA=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") && \
OPENCV_LIBRARY_ANACONDA=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))")

报错内容如下:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_nppicom_LIBRARY (ADVANCED)

解决办法

更新时间:2021.07.21 20:03
这里-D CUDA_nppicom_LIBRARY=true 不合理, ture不是一个有效的库文件名称,建议随机选一个本机有的库,比如改成-D CUDA_nppicom_LIBRARY=stdc++ 防止链接库时导致找不到libtrue.so报错

完整命令:

cmake \
-D INCLUDE_DIRS=${OPENCV_INCLUDE_DIR_ANACONDA} $INCLUDE_DIRS \
-D LIBRARY_DIRS=$OPENCV_LIBRARY_ANACONDA $LIBRARY_DIRS \
-D BUILD_PYTHON_SUPPORT=ON \
-D BUILD_DOCS=ON \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-D CMAKE_INSTALL_PREFIX=/usr/local/opencv \
-D OPENCV_EXTRA_MODULES_PATH=/home/timber/Library/opencv_contrib/modules \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_python2=OFF \
-D PYTHON3_EXECUTABLE=${OPENCV_PYTHON_EXECUTABLE_ANACONDA} \
-D PYTHON3_INCLUDE_DIR=${OPENCV_INCLUDE_DIR_ANACONDA} \
-D PYTHON3_PACKAGES_PATH=${OPENCV_PACKAGE_ANACONDA} \
-D BUILD_EXAMPLES=OFF \
-D WITH_GTK=ON \
-D WITH_GTK_2_X=ON \
-D WITH_IPP=ON \
-D BUILD_TIFF=ON \
-D BUILD_opencv_cvv=OFF \
-D INSTALL_CREATE_DISTRIB=ON \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D WITH_TBB=ON \
-D WITH_QT=ON \
-D WITH_OPENGL=ON \
-D WITH_CUDA=ON \
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
-D CMAKE_LIBRARY_PATH=/usr/local/cuda/lib64/stubs \
-D CUDA_ARCH_BIN="8.6" \
-D CUDA_ARCH_PTX="" \
-D WITH_CUBLAS=ON \
-D WITH_NVCUVID=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
-D CMAKE_BUILD_TYPE=Release \
-D CUDA_nppicom_LIBRARY=stdc++ \
..

结果:

posted @ 2021-07-21 16:54  Geoffrey_one  阅读(3830)  评论(1编辑  收藏  举报
/*
*/