简体   繁体   中英

CMake: CUDA libraries not found when compiling OpenCV

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

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_LIBRARY error.

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.

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.

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

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

It's a "Win32 or x64" architecture problem. 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.

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\\x64 rather 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.


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.

For the Linux, I solved by these step:

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

(2) Make symlink like 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.

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_TOOLKIT_ROOT_DIR C:/Program Files/NVIDIA GPU Computing Toolkit/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; so I change my environment path,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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