OpenCVConfig.cmake and CUDA on windows hardcoded path (Bug #2120)


Added by stathis -- over 12 years ago. Updated over 12 years ago.


Status:Done Start date:2012-07-02
Priority:Normal Due date:
Assignee:Marina Kolpakova % Done:

0%

Category:gpu (cuda)
Target version:2.4.3
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

I'm compiling OpenCV v2.4.9 (svn) statically with CUDA support on Windows 7. The OpenCVConfig.cmake generated adds the absolute path of the cuda libraries, but if the cuda toolkit is installed in the default location this path contains spaces, therefore subsequent use of OpenCV with an end-user application fails with:

NMAKE : fatal error U1073: don't know how to make 'C:\Program'
Stop.
NMAKE : fatal error U1077: 'D:\dev\msvc2010\VC\BIN\amd64\nmake.exe' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'D:\dev\msvc2010\VC\BIN\amd64\nmake.exe' : return code '0x2'
Stop.

this is because of the spaces. Here is an excerpt from OpenCVConfig.cmake:

set(OpenCV_opencv_core_EXTRA_DEPS_OPT C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v4.2/lib/x64/cudart.lib;C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v4.2/lib/x64/cuda.lib;C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v4.2/lib/x64/npp.lib)
set(OpenCV_opencv_imgproc_LIBNAME_OPT "opencv_imgproc249.lib")
set(OpenCV_opencv_imgproc_DEPS_OPT zlib;opencv_core)
set(OpenCV_opencv_imgproc_EXTRA_DEPS_OPT C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v4.2/lib/x64/cudart.lib;C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v4.2/lib/x64/cuda.lib;C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v4.2/lib/x64/npp.lib)

So the problem is for every OpenCV_<module>_EXTRA_DEPS_OPT variable. I think a better way to do this, would be to instead use the CUDA_PATH environment variable that the installer of the CUDA toolkit sets (at least on windows). This on my system is:

CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\

so for instance

$ENV{CUDA_PATH}/lib/Win32 for the x86 arch
$ENV{CUDA_PATH}/lib/x64 for x64 arch

This enables moving OpenCV static to another system, with potentially a different CUDA_PATH, currently this isn't possible at all.


Associated revisions

Revision 7cfb7bc8
Added by Vadim Pisarevsky about 11 years ago

Merge pull request #2120 from prclibo:master

History

Updated by Martin Reinhardt over 12 years ago

Is there any short workaround till a bugfix will appear? Even manual changing the file is possible for me. I'm not very experienced with such things and just start to write own CMakeLists. I really need the CPU acceleration. I have the same problem and right now I just use another opencv-configuration.
Thanks in advance for some help.

Updated by Marina Kolpakova over 12 years ago

  • Category changed from build/install to gpu (cuda)
  • Assignee changed from Alexander Shishkov to Marina Kolpakova

Updated by stathis -- over 12 years ago

Martin Reinhardt wrote:

Is there any short workaround till a bugfix will appear? Even manual changing the file is possible for me. I'm not very experienced with such things and just start to write own CMakeLists. I really need the CPU acceleration. I have the same problem and right now I just use another opencv-configuration.
Thanks in advance for some help.

Yes there is a simple workaround just search and replace:

C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v4.2

with the string
$ENV{CUDA_PATH}

and it will work just fine if you used the nvidia installer that sets the respective environment variables.

Updated by Anatoly Baksheev over 12 years ago

Env. variable is not good solution for case user wants to link with not default CUDA Toolkit. I think it's better just to insert quotes there.

Updated by stathis -- over 12 years ago

Adding quotes is a particularly weak solution, especially because a user cannot relocate his cuda installation prior to compiling OpenCV. I insist the correct way to do this is to use a variable. The env variable is fine and can easily be supplemented with an OpenCV variable that copies the ENV variable in case the variable is not set by the user at configure time of the end-user application.
i.e.

OPTION(USER_CUDA_PATH "User Defined CUDA Locatioin OFF)
   IF( NOT USER_CUDA_PATH )
      SET(USER_CUDA_PATH "$ENV{CUDA_PATH}")
   ENDIF()
   ...
   ...
   set(OpenCV_opencv_core_EXTRA_DEPS_OPT ${USER_CUDA_PATH}/lib/x64/cudart.lib;${USER_CUDA_PATH}/lib/x64/cuda.lib;${USER_CUDA_PATH}/lib/x64/npp.lib)
   set(OpenCV_opencv_imgproc_LIBNAME_OPT "opencv_imgproc249.lib")
  ...
  ...

Updated by stathis -- over 12 years ago

"a user cannot relocate his cuda installation prior to compiling OpenCV"
instead of "prior", I meant "after" .. sorry

Updated by Andrey Kamaev over 12 years ago

  • Target version set to 3.0

Updated by Anatoly Baksheev over 12 years ago

stathis -- wrote:

Adding quotes is a particularly weak solution, especially because a user cannot relocate his cuda installation prior to compiling OpenCV. I insist the correct way to do this is to use a variable. The env variable is fine and can easily be supplemented with an OpenCV variable that copies the ENV variable in case the variable is not set by the user at configure time of the end-user application.
i.e.
[...]

This is also weak solution. The config was designed in assumtions that paths to libraries won't be changed, and user's build scripts will pick up them in the same location. The same problems will appear with any library OpenCV depends on. For example with TBB. I think we won't fix this.

Current master version adds backslashes before each space. Are compilations errros still appear? If not, i'll close this issue next week.

Updated by Marina Kolpakova over 12 years ago

Fixed in current master. OpenCV config sets patch for CUDA libraries according to findCuda results. See 6b19c762

  • Target version changed from 3.0 to 2.4.3
  • Status changed from Open to Done

Also available in: Atom PDF