如何在可执行文件中嵌入openCV Dll。
How to embedd openCV Dll's in Executable
我使用openCV编写了一个图像匹配工具(控制台应用程序,没有gui或windows)。我想将我的EXE文件移植到另一台计算机,但它要求opencv dll (opencv_core220.dll, opencv_highgui220.dll,…)
我的问题是怎么做。我觉得有两种方法都很好:- 将opencv重新编译为静态库。Lib而不是.dll)。那没有用。我得到了关于cap_vfw.obj的10个链接错误
- 如果可能,如何合并/嵌入DLL到exe文件
我试图使用ILMerge,但它不起作用(错误:无法从a.exe文件加载程序集),因为它是专为。net设计的
注:-我使用visual studio 2005,在windows上,c++编译器,openCV 2.2
我找到了答案。您必须打开原始的openCV项目,并在静态库模式下重新编译所有相关部分。
- 对每个项目从
libjasper
开始按字母顺序执行直到opencv_video
。zlib
项目 也做同样的事情 - 对于每个项目,进入project propertiesconfiguration propertiesgeneralconfiguration type并将其设置为静态库 现在重新编译这些项目。它们将创建许多大的库文件(最多10MB)。这些文件主要位于opencv的
- 你必须在你的代码中包含更多的库,而不是当你编译dll的 下面是一个例子,你的代码应该是这样的。对不起,它的格式不太好。可能是本页的html错误:
modules
目录下。你必须找到他们,并复制到目录,当你保存你的常规库文件时,编译dll的。现在是一个棘手的部分#include "cv.h"
#include "highgui.h"
using namespace std;
using namespace cv;
// Directives to linker to include openCV lib files.
#ifndef STATIC_LIBRARY_LINK
// Linking against DLL. For each 'lib' file that appears below, final EXE will need a DLL.
// Core of openCV
#pragma comment(lib, "opencv_core220.lib")
#pragma comment(lib, "opencv_highgui220.lib")
#pragma comment(lib, "opencv_imgproc220.lib")
// Calibration and image matching
#pragma comment(lib, "opencv_flann220.lib")
#pragma comment(lib, "opencv_features2d220.lib")
#pragma comment(lib, "opencv_calib3d220.lib")
// Other libs that might be needed
/*#pragma comment(lib, "opencv_gpu220.lib")
#pragma comment(lib, "opencv_video220.lib")
#pragma comment(lib, "opencv_legacy220.lib")
#pragma comment(lib, "opencv_ml220.lib")
#pragma comment(lib, "opencv_objdetect220.lib")
#pragma comment(lib, "opencv_ffmpeg220.lib")
#pragma comment(lib, "opencv_contrib220.lib") */
#else
// Static linking. No DLL's would be required but EXE file will be bigger
// and linking in debug mode might produce many warnings since *.pdb are not always
// present with the lib files
// Core of openCV. Must be compiled as lib and not as dll's
#pragma comment(lib, "opencv_core.lib")
#pragma comment(lib, "opencv_highgui.lib")
#pragma comment(lib, "opencv_imgproc.lib")
// Calibration and image matching. Must be compiled as lib and not as dll's
#pragma comment(lib, "opencv_flann.lib")
#pragma comment(lib, "opencv_features2d.lib")
#pragma comment(lib, "opencv_calib3d.lib")
// Image I/O auxillary libraries. Must be compiled as lib and not as dll's
#pragma comment(lib, "libtiff.lib")
#pragma comment(lib, "libpng.lib")
#pragma comment(lib, "zlib.lib")
#pragma comment(lib, "libjasper.lib")
#pragma comment(lib, "libjpeg.lib")
// OpenCV linear algebra methods. Must be compiled as lib and not as dll's
#pragma comment(lib, "opencv_lapack.lib")
// Auxillary libs, found in visual studio microsoft sdk
#pragma comment(lib, "vfw32.lib")
#pragma comment( lib, "comctl32.lib" )
//#pragma comment(lib, "window_w32.lib") // Not needed
#endif
int main(void){
// Your code here
return 0;
}
您要查找的术语是静态链接。"DLL"代表"动态链接库",与静态相反。不能静态链接动态链接的库。你需要一个"普通"的库。
转到您正在构建的项目的属性(在解决方案资源管理器中右键单击项目并选择属性)。现在展开Configuration properties->Linker选项,并在General下设置静态链接库的路径(即,扩展名为.lib)。现在选择Configuration properties->Linker->Input选项,并键入您希望静态链接到的所有库的名称。现在重新构建项目,它们应该被链接到可执行文件中。如果文件的路径不正确,它会警告你。
相关文章:
- 加载"D:UsersPublicDocumentsopencvbuildx64vc14binopencv_world340d.dll",找不到或打开PDB文件
- 无法使用 OpenCv 3.4.5 从具有C++ dll 的网络摄像机 (rtsp) 中抓取帧
- 为什么在Visual Studio的OpenCV项目中使用/MT时仍然需要dll?
- Unity3D的OpenCV dll调用导致FPS下降
- c++调用opencv相关函数,并且被打包到dll中,c#无法调用它
- 在OpenCV_core310.dll中使用findContours函数时,OpenCV引发未处理的异常
- 从 dll 调用 opencv 垫到 Windows 表单,图像出现故障
- 打包 OpenCV DLL 以分发C++ DLL
- 如何在 LabVIEW 的 DLL 中打开 OpenCV 结构化边缘检测器的模型文件?
- QT 创建器:无法添加 OpenCV dll 库 ( "File format not recognized" )
- 尽管有静态链接,Opencv 3.2.0 .dll丢失
- 如何将opencv和其他dll文件链接到visual studio 2013的输出exe
- 将OpenCV .dll文件添加到NetBeans C QT应用程序
- openCV_FFMPEG **.opencv 2.4.11中的dll错误,用于IP摄像机访问
- 使用ITK或OpenCV库将现有的VC++项目转换为DLL是可能的吗
- OpenCV-缺少调试DLL库
- 在没有visualstudio的计算机上运行opencv dll
- 使用多线程调试 DLL (/MDd) C 运行时库生成静态 Opencv 库
- 没有找到Opencv .dll文件
- 如何在可执行文件中嵌入openCV Dll。