问题描述
我已经尝试建立OpenCV 3.1使用CMake(gui版本)启用Cuda。我已经安装Cuda版本7.5 64位和CMake自动找到正确的路径Cuda工具包。我确保WITH_CUDA值设置为ON,并按下配置。这是我对Cuda的看法:
检测到CUDA:7.5
CUDA NVCC目标标志:-gencode; 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
...
额外的依赖关系:comctl32 gdi32 ole32 setupapi ws2_32 vfw32 cudart nppc nppi npps cufft -LC:/ Program Files / NVIDIA GPU计算工具包/ CUDA / v7.5 / lib / x64
...
其他第三方库:
使用IPP:9.0.1 [9.0.1]
at:C :/OpenCV-3.1.0/opencv/sources/3rdparty/ippicv/unpack/ippicv_win
使用IPP异步:NO
使用特征:NO
使用Cuda:YES(ver 7.5)
使用OpenCL:YES
使用自定义HAL:NO
NVIDIA CUDA
使用CUFFT:YES
使用CUBLAS:NO
使用NVCUVID:NO
NVIDIA GPU arch:20 21 30 35
NVIDIA PTX archs:30
使用快速数学:YES
然后我使用Visual Studio 12 2013 Win64生成。
接下来我在Visual Studio 2013中打开新生成的OpenCV.sln项目并构建项目。它完成没有任何错误,但103警告,像这样:
LINK:warning LNK4044:unrecognized option'/ LC: / NVIDIA GPU计算工具包/ CUDA / v7.5 / lib / x64';忽略
OpenCV构建正常,我可以使用它来构建程序。我也可以包括opencv2 / core / cuda.hpp没有任何问题。但是,当我尝试使用cuda :: getDevice()我得到这个错误:
OpenCV错误:没有CUDA支持库在没有CUDA支持的情况下编译)在throw_no_cuda中,文件C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\include\opencv2 / core / private.cuda.hpp,line 97
当我从cv :: getBuildInformation()打印信息时:get:
其他第三方库:
使用IPP:9.0.1 [9.0.1]
at:C:\ builds\master_PackSlave-win64-vc12-shared\opencv\3rdparty / ippicv / unpack / ippicv_win
使用IPP异步:NO
使用Eigen:NO
使用Cuda:NO
使用OpenCL:YES
使用自定义HAL:NO
似乎Cuda被禁用过程,但我不能弄清楚为什么。我已经尝试重新配置和重建几次具有相同的结果。
问题是CMake:它为Visual Studio生成错误的链接选项。
$ c$ b
LINK:warning LNK4044:unrecognized option'/ LC:/ Program Files / NVIDIA GPU Computing Toolkit / CUDA / v7.5 / lib / ;忽略
它应该是LIBPATH:C:而不是LC:
要解决此问题:
- 使用CMake生成解决方案
- 转到构建目录
- 打开IDE /文本编辑器,可以在此目录中进行全局搜索
- 在任何文件中出现-LC:,将其替换为-LIBPATH:C:。
======= EDIT =========
我发现问题,它是在CMakeLists.txt:
foreach(p $ {CUDA_LIBS_PATH})
set(OPENCV_LINKER_LIBS $ {OPENCV_LINKER_LIBS} -L $ {p})
endforeach()
而不是使用$ {CMAKE_LIBRARY_PATH_FLAG}
- 打开CMakeLists.txt
- 将-L替换为$ {CMAKE_LIBRARY_PATH_FLAG}
配置&用CMake生成解决方案并用VS编译。
希望它会帮助!
I have tried to build OpenCV 3.1 using CMake (the gui version) to enable Cuda. I have installed Cuda version 7.5 64-bit and CMake automatically found the correct path to the Cuda toolkit. I made sure that the WITH_CUDA value was set to ON, and pressed configure. This is what I got concerning Cuda:
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
...
Extra dependencies: comctl32 gdi32 ole32 setupapi ws2_32 vfw32 cudart nppc nppi npps cufft -LC:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5/lib/x64
...
Other third-party libraries:
Use IPP: 9.0.1 [9.0.1]
at: C:/OpenCV-3.1.0/opencv/sources/3rdparty/ippicv/unpack/ippicv_win
Use IPP Async: NO
Use Eigen: NO
Use Cuda: YES (ver 7.5)
Use OpenCL: YES
Use custom HAL: NO
NVIDIA CUDA
Use CUFFT: YES
Use CUBLAS: NO
USE NVCUVID: NO
NVIDIA GPU arch: 20 21 30 35
NVIDIA PTX archs: 30
Use fast math: YES
Then I generate using Visual Studio 12 2013 Win64.
Next I open the newly generated OpenCV.sln project in Visual Studio 2013 and build the project. It completes without any errors, but 103 warnings like this:
LINK : warning LNK4044: unrecognized option '/LC:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5/lib/x64'; ignored
OpenCV builds just fine and I can build programs with it. I can also include "opencv2/core/cuda.hpp" without any problem. However, when I try to use cuda::getDevice() i get this error:
OpenCV Error: No CUDA support (The library is compiled without CUDA support) in throw_no_cuda, file C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\include\opencv2/core/private.cuda.hpp, line 97
When I print the information from cv::getBuildInformation() i get:
Other third-party libraries:
Use IPP: 9.0.1 [9.0.1]
at: C:\builds\master_PackSlave-win64-vc12-shared\opencv\3rdparty/ippicv/unpack/ippicv_win
Use IPP Async: NO
Use Eigen: NO
Use Cuda: NO
Use OpenCL: YES
Use custom HAL: NO
It seems Cuda is disabled somewhere in the process, but I can't figure out why. I have tried to reconfigure and rebuild several times with the same results. Would love some help on this!
The problem is CMake: it generates wrong link options for Visual Studio.
LINK : warning LNK4044: unrecognized option '/LC:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5/lib/x64'; ignored
It should be "LIBPATH:C:" instead of "LC:".
To fix the problem:
- Generate the solution with CMake
- Go to the build directory
- Open an IDE/Text editor which is able to do a global search in this directory
- For each occurrence of "-LC:" in any file, replace it by "-LIBPATH:C:".
========= EDIT =========
I found the problem, it is in CMakeLists.txt :
foreach(p ${CUDA_LIBS_PATH})
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} -L${p})
endforeach()
Instead of using "${CMAKE_LIBRARY_PATH_FLAG}" which automatically put -LIBPATH, someone put "-L"...
So to fix it:
- Open CMakeLists.txt
- Replace "-L" by "${CMAKE_LIBRARY_PATH_FLAG}"
Configure & Generate the solution with CMake and compile with VS.
Hope it will help!
这篇关于OpenCV不会使用CUDA构建,即使在CMake中WITH_CUDA = ON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!