CMake错误:变量设置为NOTFOUND [英] CMake Error: Variables are set to NOTFOUND

查看:992
本文介绍了CMake错误:变量设置为NOTFOUND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我首先使用cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb安装了cuda.现在,我正在尝试安装OpenCV 3.3.0,但是我遇到CMake错误:

I installed cuda first using cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb. Now I'm trying to install OpenCV 3.3.0 But i'm getting CMake Error:

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)

然后是很长的目标列表,如下所示:

And then a very long list of targets like so:

linked by target "opencv_cudev" in directory /home/jjros/opencv-3.3.0/modules/cudev

我正在使用以下命令来编译库:

I'm using this command to compile the library:

cmake 

-D CMAKE_C_COMPILER=/usr/bin/gcc-5 \ 
-D CMAKE_BUILD_TYPE=RELEASE \   
-D CMAKE_INSTALL_PREFIX=/usr/local \     
-D WITH_CUDA=ON \     
-D WITH_CUBLAS=ON \     
-D WITH_TBB=ON \    
-D WITH_V4L=ON \    
-D WITH_QT=ON \     
-D WITH_OPENGL=ON \    
-D ENABLE_FAST_MATH=1 \        
-D CUDA_FAST_MATH=1 \        
-D WITH_CUBLAS=1 \        
-D INSTALL_C_EXAMPLES=OFF \    
-D INSTALL_PYTHON_EXAMPLES=ON \        
-D BUILD_SHARED_LIBS=ON \        
-D WITH_GTK=ON \        
-D BUILD_EXAMPLES=ON \     
-D  CUDA_NVCC_FLAGS="-D_FORCE_INLINES" .. 

如何设置我的CMakeLists?怎么了?

How can set my CMakeLists? What's going wrong?

推荐答案

我尝试了以下操作,并且有效:

I tried the following and it worked:

FindCUDA.cmake库中的FindCUDA.cmake库更改为几个拆分的库.这必须在3个地方完成.请记住,此更改只是为了使其能够与CUDA 9.0一起使用,我没有进行版本检查或任何检查,如果您打算将其提供给具有不同CUDA版本的其他人,则应执行此操作.

Change in FindCUDA.cmake the nppi library to the several splitted ones. This has to be done in 3 places. Remember this change is just to make it work with CUDA 9.0, I am not doing checks for version or anything, which should be done if you plan to give it to different people with different CUDA versions.

1)查找带有以下内容的行:

1) look for the line with:

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)

2)找到这一行:

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}")

3)查找未设置的变量并添加新变量 因此,找到:

3) find the unset variables and add the new variables as well So, find:

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)

OpenCVDetectCUDA.cmake中,还必须删除不再受支持的2.0体系结构.

And also in OpenCVDetectCUDA.cmake you have to remove the 2.0 architechture which is no longer supported.

它具有:

  ...
  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")
  ...

基本上,我删除了第一个if,而第一个elif变成了if.

Basically I removed the first if and the first elif turns to an if.

如@matko所述 它还具有:

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") 

这是最后一件事. CUDA 9.0现在具有用于半浮点(cuda_fp16.h)的单独文件.这需要包含在OpenCV中.

One last thing it is needed. CUDA 9.0 has a separated file for the halffloat (cuda_fp16.h) now. This needs to be included in OpenCV.

摘自CUDA 9.0手册:

From CUDA 9.0 manual:

不受支持的功能 通用CUDA ‣CUDA库.内置函数__float2half_rn()和__half2float()已被删除.在CUDA工具包的更新后的fp16头文件中使用等效功能.

Unsupported Features General CUDA ‣ CUDA library. The built-in functions __float2half_rn() and __half2float() have been removed. Use equivalent functionality in the updated fp16 header file from the CUDA toolkit.

为此,您需要添加:

#include <cuda_fp16.h>

在头文件中

opencv-3.3.0\modules\cudev\include\opencv2\cudev\common.hpp

这是OpenCV明确补丁程序的基础.正如我之前告诉您的,它缺少的是什么,我不在乎CUDA版本(它需要IF).此外,CUDA 9.0还具有OpenCV使用的许多不推荐使用的功能...在某些时候,OpenCV团队可能会替换掉它.可能还没有使用一个或多个nppi拆分库.

This are the basics for a definite patch for OpenCV. What it is missing, well as I told you before, I do not care about CUDA versions (it needs an IF). Also, CUDA 9.0 has a bunch of deprecated functions used by OpenCV ... this probably will be replaced by the OpenCV team at some point. It is also possible that one or more of the splitted libraries of nppi is not used.

最终建议: 对于具有许多选项的这种复杂cmake,应使用ccmake(sudo apt-get install cmake-curses-gui)以便能够轻松更改变量或至少查看值,或使用真正的GUI.

Final recommendations: For this kind of complex cmakes with so many options you should use ccmake (sudo apt-get install cmake-curses-gui) to be able to change easily the variables or at least view the values, or a real GUI one.

对于使用Windows和Visual Studio 7的其他人,我还必须更改CUDA_HOST_COMPILER变量,否则您会在cmd.exe exit with code 1或类似内容中遇到很多错误...似乎无法解决.自动检测到的.

For other people with windows and visual studio 7, I also had to change the CUDA_HOST_COMPILER variable, else you get a bunch of errors with cmd.exe exit with code 1 or something similar... it seems it couldn't get there with the autodetected one.

这对我来说适用于OpenCV 3.3和CUDA 9.0,以及适用于Windows 10的Visual Studio2017.我认为它也应该在Ubuntu中工作,因为错误和更改与CUDA有关.我没有做太多测试,我编译并运行了一些性能测试,所有这些测试都通过了……所以我认为一切正常.

This worked for me with OpenCV 3.3 and CUDA 9.0 and Visual Studio 2017 with Windows 10. I think it should work also in Ubuntu, since the error and the changes are related to CUDA. I haven't tested it much, I compiled and run the some of the performance tests and all of them passed... So I think everything worked ok.

这篇关于CMake错误:变量设置为NOTFOUND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆