简体   繁体   English

CMake:编译OpenCV时找不到CUDA库

[英]CMake: CUDA libraries not found when compiling OpenCV

I am compiling OpenCV 3.0.0 with CUDA support on Windows, using CMAKE. 我正在使用CMAKE在Windows上使用CUDA支持编译OpenCV 3.0.0。 When I click "configure", errors occur as following: 单击“configure”时,会发生以下错误:

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_cufft_LIBRARY (ADVANCED)
    linked by target "opencv_hal" in directory E:/dev-lib/opencv3/sources/modules/hal
    ...
CUDA_nppc_LIBRARY (ADVANCED)
    ...
CUDA_nppi_LIBRARY (ADVANCED)
    ...
CUDA_npps_LIBRARY (ADVANCED)

I have checked "WITH_CUDA" and "WITH_CUFFT" in entries. 我在条目中检查了“WITH_CUDA”和“WITH_CUFFT”。 If I check "WITH_CUBLAS" as well, the outputs above will add one more CUDA_cublas_LIBRARY error. 如果我也检查“WITH_CUBLAS”,上面的输出将再添加一个CUDA_cublas_LIBRARY错误。

But before all these error messages it shows that 但在所有这些错误消息之前,它表明了这一点

CUDA detected: 7.5
CUDA NVCC target flags: -gencode;arch=compute_20,code=sm_20;-gencode;arch=compute_20,code=sm_21;-gencode;arch=compute_30,code=sm_30;-gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_30,code=compute_30

which indicates CUDA can be detected by CMAKE. 这表明CUDKE可以检测到CUDA。 However, those 4 libraries needed cannot be found. 但是,找不到所需的4个库。

I have installed CUDA 7.5 and compiled it with Visual Studio 2012 before. 我之前已经安装了CUDA 7.5并使用Visual Studio 2012进行了编译。 The CUDA samples run perfectly. CUDA样品运行完美。 So my CUDA libraries should be installed properly. 所以我的CUDA库应该正确安装。

I wonder even if I have to set these values manually, how should I do it? 我想知道即使我必须手动设置这些值,我该怎么办呢?

My specs: Windows 7 x64, Visual Studio 2012, CMAKE 3.4.0, CUDA Toolkit 7.5 我的规格:Windows 7 x64,Visual Studio 2012,CMAKE 3.4.0,CUDA Toolkit 7.5

Thanks to tips from Drop in the comments, I solved this problem. 感谢评论中Drop的提示,我解决了这个问题。 In order to close this question, I'm answering my own question. 为了结束这个问题,我正在回答我自己的问题。

It's a "Win32 or x64" architecture problem. 这是一个“Win32或x64”架构问题。 Since NVIDIA only provides cufft , nvblas , nppc , nppi , npps libs for x64, it's naturally impossible for CMAKE to find these libs for configuring a Win32 OpenCV library. 由于NVIDIA仅为x64提供cufftnvblasnppcnppinpps libs,因此CMAKE自然无法找到这些用于配置Win32 OpenCV库的库。

My solution was to choose Visual Studio 11 Win64 instead of Visual Studio 11 as generator in CMAKE. 我的解决方案是在CMAKE中选择Visual Studio 11 Win64而不是Visual Studio 11作为生成器。 So that CMAKE will automatically load libs from <CUDA_DIR>\\lib\\x64 rather than <CUDA_DIR>\\lib\\Win32 . 这样CMAKE将自动从<CUDA_DIR>\\lib\\x64而不是<CUDA_DIR>\\lib\\Win32加载库。 Further more, I also need to load all the other libs required by OpenCV in 64 bit version, such as OpenGL. 此外,我还需要加载OpenCV在64位版本中所需的所有其他库,例如OpenGL。 I will also need to compile OpenCV in x64 architecture. 我还需要在x64架构中编译OpenCV。 All the code I'm going to write in the future will have to build and debug in x64 only. 我将来要写的所有代码都只需要在x64中构建和调试。


Should one have no trouble reading Chinese materials, I'm happy to provide a link towards a post regarding the complete guide on building OpenCV 3.0 on VS2012 with CUDA supports. 如果您在阅读中文资料时没有遇到任何问题,我很乐意提供一个关于在VS2012上使用CUDA支持构建OpenCV 3.0的完整指南的帖子链接

For the Linux, I solved by these step: 对于Linux,我通过这些步骤解决了:

(1) Check .so file in the lib folder,such as cuda7-cudnn3/lib64 (1)检查lib文件夹中的.so文件,例如cuda7-cudnn3 / lib64

(2) Make symlink like sudo ln -s libcublas.so.7.5.18 libcublas.so (2)使用像sudo ln -s libcublas.so.7.5.18 libcublas.so这样的符号链接

For my case, I put correctly link in CMakeLists.txt and Makefile.config, but there wasn't a .so file. 对于我的情况,我在CMakeLists.txt和Makefile.config中正确链接,但没有.so文件。

it is really related to version!!! 它真的与版本有关!!! if you want to compile with Cuda, when you cmake opencv2413, you will notice the makefile will try to find some third-party libs for supporting more functions: 如果你想用Cuda编译,当你使用opencv2413时,你会发现makefile会试图找到一些第三方库来支持更多的功能:

CUDA_TOOLKIT_ROOT_DIR C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0 CUDA_TOOLKIT_ROOT_DIR C:/ Program Files / NVIDIA GPU计算工具包/ CUDA / v9.0

from that, I know I ever installed CUDA v9.0, but I still got this not found opencv_dep_CUDA_nppi_LIBRARY error, so I look for it in C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.0\\lib\\x64, I did can not get it whose name is nppi.lib ,so just for a test, i create a empty file and name it nppi.lib ,as I guess, I worked, but in fact, it was not enough, the test can not help compiling opencv,morever, I found I had CUDA v8, and suprisly, I got the lib nppi.lib in C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\lib\\x64; 从那以后,我知道我曾经安装过CUDA v9.0,但我仍然没有找到opencv_dep_CUDA_nppi_LIBRARY错误,所以我在C:\\ Program Files \\ NVIDIA GPU Computing Toolkit \\ CUDA \\ v9.0 \\ lib \\ x64中找到它,我做的不能得到它的名字是nppi.lib ,所以只是为了测试,我创建一个空文件,并将其命名为nppi.lib ,因为我猜,我工作,但实际上,这还不够,测试可以无法编译opencv,更多,我发现我有CUDA v8,而且很奇怪,我在C:\\ Program Files \\ NVIDIA GPU Computing Toolkit \\ CUDA \\ v8.0 \\ lib \\ x64中获得了lib nppi.lib ; so I change my environment path, 所以我改变了我的环境路径,

CUDA_TOOLKIT_ROOT_DIR C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0 then I reconfigured it. CUDA_TOOLKIT_ROOT_DIR C:/ Program Files / NVIDIA GPU Computing Toolkit / CUDA / v8.0然后我重新配置了它。 it worked!! 有效!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM