OPENCV249 编译静态库(含CUDA,OPENCL)

废话不多说直接上料:


1. 首先官网下载安装包 http://opencv.org/downloads.html


测试环境: WIN10 CUDA6.0 OPENCV2.4.9 VS2010 CMAKE3.1.0


2.解压压缩包至D:opencv下,

3.使用CMAKE编译,选择source code 目录以及需要编译的目录

因为我们这里是编译静态库故为了节省时间我们去掉 BUILD下的 BUILD_SHARED_LIBS,同时CUDA 选择动态分离式编译方式,勾选CUDA_SEPARABLE_COMPILATION,这里是为了后续动态并行,但也给后续编译工程带来了问题,需要将.cu包含进去。

OPENCV249 编译静态库(含CUDA,OPENCL)_第1张图片


4.编译工程:

这里只需要编译3rdparty 以及 modules ,最后生成INSTALL即可。

按住ctrl键,选中需要编译的项目,注意确认 项目->属性配置属性->c/c++->代码生成选项,在右侧窗口中的运行时库中选择多线程调试(/MTd) Release 模式是/MT。

OPENCV249 编译静态库(含CUDA,OPENCL)_第2张图片


最后在编译目标下生成install文件夹以及staticlib

致此编译工作结束,编译过程中的error:

1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: The command "setlocal
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: "C:\Program Files (x86)\CMake\bin\cmake.exe" -DBUILD_TYPE=Release -P cmake_install.cmake
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: :cmEnd
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: :cmErrorLevel
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: exit /b %1
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: :cmDone
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: :VCEnd" exited with code 1.

我直接无视过了,编译过很多次每次都是这样,不知道哪位解决了这个问题,不过这个无关紧要不影响编译。


下面是如何建立工程使用静态库编译

需要链接以下库:

#ifdef _DEBUG
#define LINK_MULTI(a)      #a##"249d.lib"
#pragma comment(lib,LINK_MULTI(opencv_core))
#pragma comment(lib,LINK_MULTI(opencv_highgui))
#pragma comment(lib,LINK_MULTI(opencv_video))
#pragma comment(lib,LINK_MULTI(opencv_imgproc))
#pragma comment(lib,LINK_MULTI(opencv_objdetect))
#pragma comment(lib,LINK_MULTI(opencv_ml))
#pragma comment(lib,LINK_MULTI(opencv_legacy))
#pragma comment(lib,LINK_MULTI(opencv_features2d))
#pragma comment(lib,LINK_MULTI(opencv_nonfree))
#pragma comment(lib,LINK_MULTI(opencv_stitching))
#pragma comment(lib,LINK_MULTI(opencv_calib3d))
#pragma comment(lib,LINK_MULTI(opencv_contrib))
#pragma comment(lib,LINK_MULTI(opencv_flann))

#pragma comment(lib, "zlibd.lib")
#pragma comment(lib, "libtiffd.lib")
#pragma comment(lib, "libpngd.lib")
#pragma comment(lib, "libjpegd.lib")
#pragma comment(lib, "libjasperd.lib")
#pragma comment(lib, "IlmImfd.lib")
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "vfw32.lib")
#else
#define LINK_MULTI(a)      #a##"249.lib"
#pragma comment(lib,LINK_MULTI(opencv_core))
#pragma comment(lib,LINK_MULTI(opencv_highgui))
#pragma comment(lib,LINK_MULTI(opencv_video))
#pragma comment(lib,LINK_MULTI(opencv_imgproc))
#pragma comment(lib,LINK_MULTI(opencv_objdetect))
#pragma comment(lib,LINK_MULTI(opencv_ml))
#pragma comment(lib,LINK_MULTI(opencv_legacy))
#pragma comment(lib,LINK_MULTI(opencv_features2d))
#pragma comment(lib,LINK_MULTI(opencv_nonfree))
#pragma comment(lib,LINK_MULTI(opencv_stitching))
#pragma comment(lib,LINK_MULTI(opencv_calib3d))
#pragma comment(lib,LINK_MULTI(opencv_flann))
#pragma comment(lib, "zlib.lib")
#pragma comment(lib, "libtiff.lib")
#pragma comment(lib, "libpng.lib")
#pragma comment(lib, "libjpeg.lib")
#pragma comment(lib, "libjasper.lib")
#pragma comment(lib, "IlmImf.lib")
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "vfw32.lib")
#endif


如果在编译时提示error:

1>opencv_core249.lib(cuda_compile_generated_matrix_operations.cu.obj) : error LNK2001: unresolved external symbol ___cudaRegisterLinkedBinary_64_tmpxft_0000e530_00000000_14_matrix_operations_compute_35_cpp1_ii_d262f657

那就是因为我们没有添加.cu文件,添加matrix_operations.cu路径在D:\opencv\opencv249\sources\modules\dynamicuda\src\cuda下

注意此时将工程生成自定义中规则选择为CUDA

OPENCV249 编译静态库(含CUDA,OPENCL)_第3张图片


你可能感兴趣的:(OPENCV,CUDA,OPENCL)