ubuntu18.04+cuda9.0+boost下安装opencv3.2.0问题解决

1. CUDA_nppi_LIBRARY问题

报错信息为:

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)

这是因为

× 在cuda9.0中,nppi被分割成其他的小部分

× cuda 不再使用fermi,不兼容cuda2.0

解决方法:

(1) 修改opencv-3.2.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)修改opencv-3.2.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)cuda9.0手册中描述:__float2half_rn() 和 __half2float() 函数被删除,加入fp16头文件来实现同样的功能。所以在opencv-3.2.0/modules/cudev/include/opencv2/cudev/common.hpp中

加入:

#include <cuda_fp16.h>

然后使用

cd ~/opencv-3.2.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j7
sudo install

2. gcc version问题

报错信息为

unsupported GNU version! gcc versions later than 6 are not supported

这是因为gcc和g++版本过高,需要降级。

解决方法为:

sudo apt install gcc-6 g++-6
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 7

需要注意的是gcc和g++的版本需要一致。之前使用gcc-4.8和gcc-6.5无法通过cmake

 

3. /tmp/tmpxft_000024a_00000000问题

make的时候出现

100 errors detected in the compilation of "/tmp/tmpxft_0000024a_00000000-21_gpu_mat.compute_61.cpp1.ii". Compilation terminated. CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:266 (message): Error generating file /home/USERNAME/opencvdir/opencv/build/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o

这是因为c++11的问题

解决方法:

加上允许c++11的指令重新编译

cd ~/opencv-3.2.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_NVCC_FLAGS="-std=c++11 --expt-relaxed-constexpr" ..
make -j7
sudo install

4.regfreeA, regexecA, regcompA问题

因为我同时安装了boost库,所以make的时候出现了以下报错信息

ts_gtest.cpp:(.text._ZN7testing8internal2RED2Ev+0xf): undefined reference to 'regfreeA'.

这是因为与boost里的regex.h文件冲突了。

解决方法为:

× 修改bashrc里关于boost的环境变量

export C_INCLUDE_PATH=
export CPLUS_INCLUDE_PATH=

因为我的c_include_path里面只包含了boost的路径,所以直接置空了。

× 如果不行,可以尝试先把boost里的regex.h文件改名,编译好了opencv再改回去。

sudo mv /usr/local/include/boost/regex.h /usr/local/include/boost/regex_boost.h

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值