【Ubuntu版】源码安装opencv(一)
参考资料:
linux ubuntu16.04 opencv3.4.2 cuda9 安装编译填坑记
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_nppi_LIBRARY (ADVANCED)
linked by target "opencv_cudev" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudev
linked by target "opencv_cudev" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudev
linked by target "opencv_test_cudev" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudev/test
linked by target "opencv_core" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/core
linked by target "opencv_core" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/core
linked by target "opencv_test_core" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/core
linked by target "opencv_perf_core" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/core
linked by target "opencv_test_cudaarithm" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaarithm
linked by target "opencv_perf_cudaarithm" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaarithm
linked by target "opencv_cudaarithm" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaarithm
linked by target "opencv_cudaarithm" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaarithm
linked by target "opencv_test_flann" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/flann
linked by target "opencv_flann" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/flann
linked by target "opencv_flann" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/flann
linked by target "opencv_imgproc" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/imgproc
linked by target "opencv_imgproc" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/imgproc
linked by target "opencv_test_imgproc" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/imgproc
linked by target "opencv_perf_imgproc" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/imgproc
linked by target "opencv_test_ml" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/ml
linked by target "opencv_ml" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/ml
linked by target "opencv_ml" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/ml
linked by target "opencv_test_objdetect" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/objdetect
linked by target "opencv_objdetect" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/objdetect
linked by target "opencv_objdetect" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/objdetect
linked by target "opencv_perf_objdetect" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/objdetect
linked by target "opencv_video" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/video
linked by target "opencv_video" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/video
linked by target "opencv_test_video" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/video
linked by target "opencv_perf_video" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/video
linked by target "opencv_test_cudabgsegm" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudabgsegm
linked by target "opencv_cudabgsegm" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudabgsegm
linked by target "opencv_cudabgsegm" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudabgsegm
linked by target "opencv_perf_cudabgsegm" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudabgsegm
linked by target "opencv_test_cudafilters" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudafilters
linked by target "opencv_cudafilters" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudafilters
linked by target "opencv_cudafilters" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudafilters
linked by target "opencv_perf_cudafilters" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudafilters
linked by target "opencv_test_cudaimgproc" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaimgproc
linked by target "opencv_perf_cudaimgproc" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaimgproc
linked by target "opencv_cudaimgproc" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaimgproc
linked by target "opencv_cudaimgproc" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaimgproc
linked by target "opencv_test_cudawarping" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudawarping
linked by target "opencv_cudawarping" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudawarping
linked by target "opencv_cudawarping" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudawarping
linked by target "opencv_perf_cudawarping" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudawarping
linked by target "opencv_test_dnn" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/dnn
linked by target "opencv_dnn" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/dnn
linked by target "opencv_dnn" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/dnn
linked by target "opencv_perf_dnn" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/dnn
linked by target "opencv_test_imgcodecs" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/imgcodecs
linked by target "opencv_imgcodecs" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/imgcodecs
linked by target "opencv_imgcodecs" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/imgcodecs
linked by target "opencv_perf_imgcodecs" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/imgcodecs
linked by target "opencv_test_photo" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/photo
linked by target "opencv_photo" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/photo
linked by target "opencv_photo" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/photo
linked by target "opencv_perf_photo" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/photo
linked by target "opencv_test_shape" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/shape
linked by target "opencv_shape" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/shape
linked by target "opencv_shape" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/shape
linked by target "opencv_test_videoio" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/videoio
linked by target "opencv_videoio" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/videoio
linked by target "opencv_videoio" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/videoio
linked by target "opencv_perf_videoio" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/videoio
linked by target "opencv_test_cudacodec" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudacodec
linked by target "opencv_cudacodec" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudacodec
linked by target "opencv_cudacodec" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudacodec
linked by target "opencv_perf_cudacodec" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudacodec
linked by target "opencv_test_highgui" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/highgui
linked by target "opencv_highgui" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/highgui
linked by target "opencv_highgui" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/highgui
linked by target "opencv_ts" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/ts
linked by target "opencv_ts" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/ts
linked by target "opencv_test_features2d" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/features2d
linked by target "opencv_features2d" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/features2d
linked by target "opencv_features2d" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/features2d
linked by target "opencv_perf_features2d" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/features2d
linked by target "opencv_test_calib3d" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/calib3d
linked by target "opencv_calib3d" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/calib3d
linked by target "opencv_calib3d" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/calib3d
linked by target "opencv_perf_calib3d" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/calib3d
linked by target "opencv_test_cudafeatures2d" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudafeatures2d
linked by target "opencv_perf_cudafeatures2d" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudafeatures2d
linked by target "opencv_cudafeatures2d" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudafeatures2d
linked by target "opencv_cudafeatures2d" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudafeatures2d
linked by target "opencv_test_cudalegacy" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudalegacy
linked by target "opencv_cudalegacy" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudalegacy
linked by target "opencv_cudalegacy" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudalegacy
linked by target "opencv_perf_cudalegacy" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudalegacy
linked by target "opencv_test_cudaobjdetect" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaobjdetect
linked by target "opencv_cudaobjdetect" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaobjdetect
linked by target "opencv_cudaobjdetect" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaobjdetect
linked by target "opencv_perf_cudaobjdetect" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaobjdetect
linked by target "opencv_test_cudaoptflow" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaoptflow
linked by target "opencv_cudaoptflow" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaoptflow
linked by target "opencv_cudaoptflow" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaoptflow
linked by target "opencv_perf_cudaoptflow" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudaoptflow
linked by target "opencv_test_cudastereo" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudastereo
linked by target "opencv_perf_cudastereo" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudastereo
linked by target "opencv_cudastereo" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudastereo
linked by target "opencv_cudastereo" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/cudastereo
linked by target "opencv_test_stitching" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/stitching
linked by target "opencv_perf_stitching" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/stitching
linked by target "opencv_stitching" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/stitching
linked by target "opencv_stitching" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/stitching
linked by target "opencv_superres" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/superres
linked by target "opencv_superres" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/superres
linked by target "opencv_test_superres" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/superres
linked by target "opencv_perf_superres" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/superres
linked by target "opencv_test_videostab" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/videostab
linked by target "opencv_videostab" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/videostab
linked by target "opencv_videostab" in directory /home/yichao/360Downloads/opencv-4.1.0/modules/videostab
linked by target "opencv_traincascade" in directory /home/yichao/360Downloads/opencv-4.1.0/apps/traincascade
linked by target "opencv_createsamples" in directory /home/yichao/360Downloads/opencv-4.1.0/apps/createsamples
linked by target "opencv_annotation" in directory /home/yichao/360Downloads/opencv-4.1.0/apps/annotation
linked by target "opencv_visualisation" in directory /home/yichao/360Downloads/opencv-4.1.0/apps/visualisation
linked by target "opencv_interactive-calibration" in directory /home/yichao/360Downloads/opencv-4.1.0/apps/interactive-calibration
linked by target "opencv_version" in directory /home/yichao/360Downloads/opencv-4.1.0/apps/version
Generating done
参考资料
[CMake Error: Variables are set to NOTFOUND](https://stackoverflow.com/questions/46584000/cmake-error-variables-are-set-to-notfound)
[OpenCV3.3+CUDA9.0+Cmake3.9 环境搭建](https://blog.csdn.net/u014613745/article/details/78310916)
解决方法:
1. 修改 FindCUDA.cmake 文件
sudo gedit /home/yichao/360Downloads/opencv-4.1.0/cmake/FindCUDA.cmake
find_cuda_helper_libs(nppi)
修改为
find_cuda_helper_libs(nppial)
find_cuda_helper_libs(nppicc)
find_cuda_helper_libs(nppicom)
find_cuda_helper_libs(nppidei)
find_cuda_helper_libs(nppif)
find_cuda_helper_libs(nppig)
find_cuda_helper_libs(nppim)
find_cuda_helper_libs(nppist)
find_cuda_helper_libs(nppisu)
find_cuda_helper_libs(nppitc)
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")
修改为
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")
unset(CUDA_nppi_LIBRARY CACHE)
修改为
unset(CUDA_nppial_LIBRARY CACHE)
unset(CUDA_nppicc_LIBRARY CACHE)
unset(CUDA_nppicom_LIBRARY CACHE)
unset(CUDA_nppidei_LIBRARY CACHE)
unset(CUDA_nppif_LIBRARY CACHE)
unset(CUDA_nppig_LIBRARY CACHE)
unset(CUDA_nppim_LIBRARY CACHE)
unset(CUDA_nppist_LIBRARY CACHE)
unset(CUDA_nppisu_LIBRARY CACHE)
unset(CUDA_nppitc_LIBRARY CACHE)
2. 修改 OpenCVDetectCUDA.cmake 文件
sudo gedit /home/yichao/360Downloads/opencv-4.1.0/cmake/OpenCVDetectCUDA.cmake
...
set(__cuda_arch_ptx "")
if(CUDA_GENERATION STREQUAL "Fermi")
set(__cuda_arch_bin "2.0")
elseif(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin "3.0 3.5 3.7")
...
修改为
...
set(__cuda_arch_ptx "")
if(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin "3.0 3.5 3.7")
elseif(CUDA_GENERATION STREQUAL "Maxwell")
set(__cuda_arch_bin "5.0 5.2")
...
set(__cuda_arch_bin "2.0 3.0 3.5 3.7 5.0 5.2 6.0 6.1")
替换为
set(__cuda_arch_bin "3.0 3.5 3.7 5.0 5.2 6.0 6.1")
3. 修改 common.hpp 文件
# cuda9以上版本中有一个单独的halffloat(cuda_fp16.h)头文件,也应该被包括在opencv的目录里
sudo gedit /home/yichao/360Downloads/opencv-4.1.0/modules/cudev/include/opencv2/cudev/common.hpp
添加一行
#include
4. 重新 Configure
opencv2/features2d.hpp: 没有那个文件或目录
#include "opencv2/features2d.hpp"
^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
In file included from /home/yichao/360Downloads/opencv-4.1.0/modules/stitching/include/opencv2/stitching.hpp:49:0,
from /home/yichao/360Downloads/opencv-4.1.0/modules/stitching/src/precomp.hpp:59,
from /home/yichao/360Downloads/opencv-4.1.0/opencv_build_dir/modules/stitching/opencv_stitching_pch_dephelp.cxx:1:
/home/yichao/360Downloads/opencv-4.1.0/modules/stitching/include/opencv2/stitching/detail/matchers.hpp:52:42: fatal error: opencv2/xfeatures2d/cuda.hpp: 没有那个文件或目录
方法一(推荐):
[在Ubuntu18.04中安装基于Python的OpenCV 3出现的问题总结](https://blog.csdn.net/qq_33475105/article/details/82819850)
https://github.com/opencv/opencv_contrib/issues/1534
解决方案:
修改文件
/home/yichao/360Downloads/opencv-3.3.0/modules/stitching/CMakeLists.txt
在CMakeLists.txt增加以下内容:
INCLUDE_DIRECTORIES("/home/yichao/360Downloads/opencv-3.3.0/opencv_contrib-3.3.0/modules/xfeatures2d/include")
方法二:
解决办法:
1. 搜索 cuda.hpp 文件在哪个文件夹
/usr/local/opencv4.1.0/include/opencv2/xfeatures2d/cuda.hpp
2. 新建 xfeatures2d 文件夹
mkdir /usr/include/opencv2/xfeatures2d/cuda.hpp
3. 创建软链接
sudo ln -s /usr/local/opencv4.1.0/include/opencv2/xfeatures2d/cuda.hpp /usr/include/opencv2/xfeatures2d/cuda.hpp
如果缺少的文件太多了,可能是编译opencv路径错误,尝试用终极方法:
# 创建软链接
sudo ln -s /usr/local/opencv4.1.0/include/opencv2 /usr/include/opencv2
错误原因:
编译与GPU/CUDA有关
解决办法:
cmake编译的时候,最后指定使用Kepler
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler ..
-- Configuring incomplete, errors occurred!
CMake Error: Cannot open file for write: /home/yichao/360Downloads/opencv-4.1.0/opencv_build_dir/CMakeCache.txt.tmp
CMake Error: : System Error: Permission denied
CMake Error: Unable to open cache file for save. /home/yichao/360Downloads/opencv-4.1.0/opencv_build_dir/CMakeCache.txt
CMake Error: : System Error: Permission denied
错误原因:
在新建 opencv_build_dir 目录的时候,我执行的指令是:
sudo mkdir opencv_build_dir
opencv_build_dir 文件夹属于 root 用户组,文件夹被锁住
解决办法:
1. 删除 opencv_build_dir 目录
sudo rm -rf opencv_build_dir
2. 新建 opencv_build_dir 目录
mkdir opencv_build_dir
CMake Error at cmake/OpenCVModule.cmake:305 (message):
No extra modules found in folder:
/home/yichao/360Downloads/opencv-4.1.0/opencv_contrib/modules
Please provide path to 'opencv_contrib/modules' folder.
解决办法:
1. 下载 opencv_contrib
下载地址:https://github.com/opencv/opencv_contrib/releases
2. 将 opencv_contrib 文件解压后放入opencv解压后的文件夹
/home/yichao/360Downloads/opencv-4.1.0/opencv_contrib-4.1.0
3. 重新 cmake
nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified
CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:206 (message):
Error generating
/home/yichao/360Downloads/opencv-4.1.0/opencv_build_dir/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o
modules/core/CMakeFiles/opencv_core.dir/build.make:63: recipe for target 'modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o' failed
make[2]: *** [modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o] Error 1
CMakeFiles/Makefile2:2288: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
解决办法:
1. 修改 OpenCVDetectCUDA.cmake 文件
sudo gedit /home/yichao/360Downloads/opencv-4.1.0/cmake/OpenCVDetectCUDA.cmake
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})
替换为
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -D_FORCE_INLINES -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})
如果上面的方法无效,考虑用cmake-gui图形化界面编译opencv,修改config配置也比较方便
CMake Error at /home/ubuntu/opencv3.1.0/opencv-3.1.0/cmake/OpenCVUtils.cmake:895 (file):
file DOWNLOAD cannot open file for write.
Call Stack (most recent call first):
/home/ubuntu/opencv3.1.0/opencv_contrib/modules/dnn_modern/CMakeLists.txt:20 (ocv_download)
CMake Error at /home/ubuntu/opencv3.1.0/opencv-3.1.0/cmake/OpenCVUtils.cmake:899 (message):
Failed to download . Status=
Call Stack (most recent call first):
/home/ubuntu/opencv3.1.0/opencv_contrib/modules/dnn_modern/CMakeLists.txt:20 (ocv_download)
-- Configuring incomplete, errors occurred!
See also "/home/ubuntu/opencv3.1.0/opencv-3.1.0/build/CMakeFiles/CMakeOutput.log".
See also "/home/ubuntu/opencv3.1.0/opencv-3.1.0/build/CMakeFiles/CMakeError.log".
[face_landmark_model.dat 下载地址](https://blog.csdn.net/qq_34806812/article/details/82501999)
解决办法:
找到(ocv_download)前面的txt,把报错的行数:
/home/ubuntu/opencv3.1.0/opencv_contrib/modules/dnn_modern/CMakeLists.txt:20
FILENAME替换为PACKAGE,继续Generate。
make[2]: *** No rule to make target `/usr/lib/libnvcuvid.so‘, needed by `lib/libopencv_cudacodec.so.3.1.0‘. Stop.
解决办法:
重新建立软连接。
[ 34%] Linking CXX shared library ../../lib/libopencv_videoio.so
/usr/bin/ld: /usr/local/lib/libavformat.a(allformats.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavformat.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:386: recipe for target 'lib/libopencv_videoio.so.3.4.2' failed
make[2]: *** [lib/libopencv_videoio.so.3.4.2] Error 1
CMakeFiles/Makefile2:11230: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/all' failed
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
解决办法:
不管是libavformat.a还是 libavcodec.a 、libavutil.a或libswscale.a引起的报错,都可以先把这几个文件从/usr/local/lib中移动别处先放着,等到编译完成了再放回去。
[ 88%] Linking CXX executable ../../bin/example_gpu_multi
/usr/bin/ld: CMakeFiles/example_gpu_multi.dir/multi.cpp.o: undefined reference to symbol '_ZN3tbb18task_group_contextD1Ev'
//usr/lib/x86_64-linux-gnu/libtbb.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
samples/gpu/CMakeFiles/example_gpu_multi.dir/build.make:122: recipe for target 'bin/example_gpu_multi' failed
make[2]: *** [bin/example_gpu_multi] Error 1
CMakeFiles/Makefile2:47768: recipe for target 'samples/gpu/CMakeFiles/example_gpu_multi.dir/all' failed
make[1]: *** [samples/gpu/CMakeFiles/example_gpu_multi.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
解决办法:
BUILD_EXAMPLES=ON,请改成=OFF
错误原因:
缺省和默认的架构是Fermi,不支持当前CUDA版本
解决办法:
指定CUDA架构和算力
-D CUDA_GENERATION=Pascal
-D CUDA_ARCH_BIN="7.5"
error while loading shared libraries: libopencv_core.so.3.0: cannot open shared object file: No such file or directory.
解决办法:
添加环境变量
sudo gedit ~/.bashrc
添加一行
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
source ~/.bashrc
sudo gedit /etc/ld.so.conf.d/opencv.conf
sudo ldconfig
sbin/ldconfig.real: /usr/lib/nvidia-375/libEGL.so.1 不是符号连接
/sbin/ldconfig.real: /usr/lib32/nvidia-375/libEGL.so.1 不是符号连接
错误原因:
这个错误可能是由于系统BUG所致
解决办法:
删除软链接,重新创建软链接
sudo mv /usr/lib/nvidia-375/libEGL.so.1 /usr/lib/nvidia-375/libEGL.so.1.org
sudo mv /usr/lib32/nvidia-375/libEGL.so.1 /usr/lib32/nvidia-375/libEGL.so.1.org
sudo ln -s /usr/lib/nvidia-375/libEGL.so.375.39 /usr/lib/nvidia-375/libEGL.so.1
sudo ln -s /usr/lib32/nvidia-375/libEGL.so.375.39 /usr/lib32/nvidia-375/libEGL.so.1
sudo gedit /etc/ld.so.conf.d/opencv.conf
sudo ldconfig
/sbin/ldconfig.real: /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn.so.7 不是符号连接
[Ubuntu ldconfig(解决*.so不是符号连接)](https://blog.csdn.net/hjxu2016/article/details/69389597)
[为什么得到“ /sbin/ldconfig.real:/usr/local/cuda/lib64/libcudnn.so.7不是符号链接”?](https://qastack.cn/ubuntu/1025928/why-do-i-get-sbin-ldconfig-real-usr-local-cuda-lib64-libcudnn-so-7-is-not-a)
解决办法:
cd /usr/local/cuda-10.2/targets/x86_64-linux/lib
# 文件备份
sudo cp libcudnn.so. libcudnn.so.old
sudo cp libcudnn.so.7 libcudnn.so.7.old
# 删除文件
sudo rm -rf libcudnn.so
sudo rm -rf libcudnn.so.7
# 创建软链接
sudo ln -s libcudnn.so.7.6.5 libcudnn.so.7
sudo ln -s libcudnn.so.7 libcudnn.so
In file included from /home/yichao/360Downloads/opencv-3.3.0/opencv_build_dir/modules/cudacodec/opencv_cudacodec_pch_dephelp.cxx:1:0:
/home/yichao/360Downloads/opencv-3.3.0/modules/cudacodec/src/precomp.hpp:59:14: fatal error: nvcuvid.h: 没有那个文件或目录
#include
^~~~~~~~~~~
compilation terminated.
[OpenCV 4.1 CUDA 10.1 linux下编译问题【fatal error: nvcuvid.h: No such file or directory】](https://blog.csdn.net/chanzhennan/article/details/90451968)
[解决方法](https://github.com/opencv/opencv_contrib/pull/1946)
错误原因:
#include 头文件在cuda10 以后就被弃了
解决方法:
1. 在英伟达官网下载组件
https://developer.nvidia.com/nvidia-video-codec-sdk#Download
2. 解压缩之后把 Video_Codec_SDK_11.1.5/Interface/ 下面的cuviddec.h 和 nvcuvid.h文件拷贝到/usr/include
cd /home/yichao/360Downloads/opencv-3.3.0/samples/cpp/example_cmake
cmake .
make
./opencv_example
# 如果显示 Hello OpenCV,表示安装成功
CMake Error at /usr/local/lib/cmake/opencv4/OpenCVModules.cmake:165 (message):
The imported target "opencv_core" references the file
"/usr/local/lib/libopencv_core.so.4.5.3"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/local/lib/cmake/opencv4/OpenCVModules.cmake"
but not all the files it references.
Call Stack (most recent call first):
/usr/local/lib/cmake/opencv4/OpenCVConfig.cmake:126 (include)
CMakeLists.txt:10 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/yichao/360Downloads/opencv-3.3.0/samples/cpp/example_cmake/CMakeFiles/CMakeOutput.log".
错误原因:
之前安装了opencv4.5.3版本,opencv4没有卸载干净,cmake找到了/usr/local/lib/cmake/opencv4,导致环境混乱
解决办法:
卸载opencv4.5.3,删除opencv4.5.3相关的文件
卸载opencv方法,参考资料:
[Ubuntu下卸载opencv](https://blog.csdn.net/m0_37605642/article/details/120111105)
sudo rm -rf /usr/local/opencv4
sudo rm -rf /usr/local/lib/cmake/opencv4