我使用openCV编写了一个图像匹配工具(控制台应用程序,没有gui或windows)。 我想将我的EXE文件移植到另一台计算机,但它要求opencv dll(opencv_core220.dll,opencv_highgui220.dll,...)
我的问题是如何做到这一点。我认为其中任何一种方式都有好处:
我尝试使用ILMerge,但它不起作用(错误:不会从a.exe文件加载程序集),因为它仅针对.Net设计
P.S。 - 我在windows,c ++编译器,openCV 2.2
上使用visual studio 2005答案 0 :(得分:7)
我找到了答案。 您必须打开原始openCV项目并在静态库模式下重新编译所有相关部分。
libjasper
开始,按字母顺序开始,直到opencv_video
。同样对zlib
项目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;
}
答案 1 :(得分:2)
您正在寻找的术语是静态链接。 “DLL”代表“动态链接库”,它与静态相反。您无法静态链接动态链接库。你需要一个“普通”的库。
答案 2 :(得分:0)
转到您正在构建的项目的属性(右键单击解决方案资源管理器中的项目和seleck propeties)。现在展开Configuration属性 - > Linker选项,在General下,设置静态链接库的路径(即扩展名为.lib)。现在选择配置属性 - >链接器 - >输入选项,然后键入要将其静态链接到的所有库的名称。现在重建项目,它们应该链接到可执行文件。如果文件的路径不正确,它会发出警告。