C++ CMake:编译 OpenCV 时找不到 CUDA 库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33097558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:12:54  来源:igfitidea点击:

CMake: CUDA libraries not found when compiling OpenCV

c++opencvcmake

提问by John Hany

I am compiling OpenCV 3.0.0 with CUDA support on Windows, using CMAKE. When I click "configure", errors occur as following:

我正在使用 CMAKE 在 Windows 上编译支持 CUDA 的 OpenCV 3.0.0。当我点击“配置”时,出现如下错误:

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. If I check "WITH_CUBLAS" as well, the outputs above will add one more CUDA_cublas_LIBRARYerror.

我在条目中检查了“WITH_CUDA”和“WITH_CUFFT”。如果我也检查“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. However, those 4 libraries needed cannot be found.

这表明 CMAKE 可以检测到 CUDA。但是,找不到所需的 4 个库。

I have installed CUDA 7.5 and compiled it with Visual Studio 2012 before. The CUDA samples run perfectly. So my CUDA libraries should be installed properly.

我之前已经安装了 CUDA 7.5 并使用 Visual Studio 2012 对其进行了编译。CUDA 示例运行完美。所以我的 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

回答by John Hany

Thanks to tips from Drop in the comments, I solved this problem. In order to close this question, I'm answering my own question.

感谢 Drop 在评论中的提示,我解决了这个问题。为了结束这个问题,我正在回答我自己的问题。

It's a "Win32 or x64" architecture problem. Since NVIDIA only provides cufft, nvblas, nppc, nppi, nppslibs for x64, it's naturally impossible for CMAKE to find these libs for configuring a Win32 OpenCV library.

这是一个“Win32 或 x64”架构问题。由于 NVIDIA 只提供x64 的cufft, nvblas, nppc, nppi,npps库,所以 CMAKE 自然不可能找到这些库来配置 Win32 OpenCV 库。

My solution was to choose Visual Studio 11 Win64 instead of Visual Studio 11 as generator in CMAKE. So that CMAKE will automatically load libs from <CUDA_DIR>\lib\x64rather than <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. I will also need to compile OpenCV in x64 architecture. All the code I'm going to write in the future will have to build and debug in x64 only.

我的解决方案是在 CMAKE 中选择 Visual Studio 11 Win64 而不是 Visual Studio 11 作为生成器。这样 CMAKE 将自动从而<CUDA_DIR>\lib\x64不是<CUDA_DIR>\lib\Win32. 此外,我还需要加载 64 位版本的 OpenCV 所需的所有其他库,例如 OpenGL。我还需要在 x64 架构中编译 OpenCV。我将来要编写的所有代码都必须仅在 x64 中构建和调试。



Should one have no trouble reading Chinesematerials, I'm happy to provide a linktowards a post regarding the complete guide on building OpenCV 3.0 on VS2012 with CUDA supports.

如果阅读中文材料没有问题,我很高兴提供一个链接,指向有关在 VS2012 上构建 OpenCV 3.0 并支持 CUDA 的完整指南的帖子。

回答by Cloud Cho

For the Linux, I solved by these step:

对于 Linux,我通过以下步骤解决了:

(1) Check .sofile in the lib folder,such as cuda7-cudnn3/lib64

(1)检查.solib文件夹下的文件,如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 .sofile.

就我而言,我在 CMakeLists.txt 和 Makefile.config 中正确放置了链接,但没有.so文件。

回答by Chuckie Pan

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编译,当你cmake 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.libin C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64; so I change my environment path,

从那以后,我知道我曾经安装过 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;所以我改变了我的环境路径,

CUDA_TOOLKIT_ROOT_DIR C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0then I reconfigured it. it worked!!

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