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

查看:67
本文介绍了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 中的 nppi 库更改为几个拆分的库.这必须在 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)

并将其替换为以下几行:

and replace it with the lines:

  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.0modulescudevincludeopencv2cudevcommon.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) 以便能够轻松更改变量或至少查看值,或者真正的图形用户界面.

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 Studio 2017.我认为它应该也适用于 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天全站免登陆