12

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

talonmies
  • 70,661
  • 34
  • 192
  • 269
John Hany
  • 620
  • 2
  • 12
  • 24
  • 2
    Are you configuring against x86 or x86_64 architecture? Is there a reason not to use precompiled binaries and to use 4 years old compiler? – Ivan Aksamentov - Drop Oct 13 '15 at 08:43
  • I'm not sure how to choose between x86 or x86_64 in CMAKE. I thought it's at the stage while compiling the whole project using MSVC. As for VS2012, I'm using it now and it still works fine.@Drop – John Hany Oct 13 '15 at 09:04
  • 1
    Nope, there will be only one platform in generated project. If you are using cmake-gui, you can choose toolchain+platform in a pop up just after you click Configure for the first time You need to delete cmake cache (in menu "File"), or to just delete build foolder to be able to select another platform again. Nvidia only provides `cufft` and `nppi` for 64 bit platform (check `\lib\` folder). – Ivan Aksamentov - Drop Oct 13 '15 at 13:27
  • And what about [pre-built OpenCV libs](http://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.0.0/)? – Ivan Aksamentov - Drop Oct 13 '15 at 13:28
  • Thanks, man. It WAS an architecture problem. I changed the generator from `Visual Studio 11` to `Visual Studio 11 Win64`, and `cufft` and all the other libs became available for CMAKE. I am compiling it for 64-bit right now. FYI, I'm compiling it myself because pre-built OpenCV libs don't include all the CUDA functions.@Drop – John Hany Oct 14 '15 at 08:31
  • @JohnHany: Would you mind to either close your question or make a proper answer and accept is? Otherwise this question looks like being not answered. – usr1234567 Oct 19 '15 at 16:12

3 Answers3

24

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.

John Hany
  • 620
  • 2
  • 12
  • 24
  • Thanks for the solution. I had the same problem using VS 14 and CUDA Toolkit v7.5. When I changed to x64, CMake found the libraries. Just a note to those of us new to the CMake GUI, you need to create a new build directory for the x64 build, and then when clicking on the Configure button it will give you the option of choosing the 64-bit compiler. Then everything proceeded nicely for me. – OnTheContrary Mar 24 '16 at 06:25
  • Or simply click `File | Delete Cache` before changing the architecture:) – John Hany Mar 31 '16 at 07:15
  • I have the same problem but using VS 2017, Cmake 3.10 and CUDA 9.0. The solution doesn't work for me! Still CUDA_nppi_LIBRARY-NOTFOUND and CUDA_nvcuvenc_LIBRARY-NOTFOUND – sgiraz Oct 14 '17 at 20:24
  • @sgira I think they are two separate issues. (1) I notice [here](https://devtalk.nvidia.com/default/topic/1024631/cuda-setup-and-installation/cmake-cuda-9-project-configurations-fails-cuda_nppi_library-is-not-available-/) indicating that `nppi` is not included in CUDA 9 or at least not as its original form. [Here](https://stackoverflow.com/a/45590780/3829845) is a solution worth trying. (2) Since OpenCV 3.0, I have been failing to compile with `NVCUVID` feature because I don't have NVENC SDK on my machine. Disabling `WITH_NVCUVID` in CMake would avoid such inconvenience. – John Hany Oct 15 '17 at 15:03
  • For my side I can add that you should install CUDA, Visual Studio and Cmake on the same drive. When I installed CUDA and Cmake on drive C and VS on drive D. Cmake wasn't able to find CUDA. – Panicum Oct 31 '19 at 16:28
1

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.

Cloud Cho
  • 1,594
  • 19
  • 22
0

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!!