I have created a new project (without code) that uses OpenCV.
I the project properties I set the requirements like below:
library directory:
C:\OpenCV-2.2.0\lib\Debug
include directories:
C:\OpenCV-2.2.0\include\opencv
C:\OpenCV-2.2.0\include\opencv2
C:\OpenCV-2.2.0\include
The first lines of code :
#pragma comment(lib, "opencv_core230d.lib")
#pragma comment(lib, "opencv_highgui230d.lib")
#pragma comment(lib, "opencv_video230d.lib")
#pragma comment(lib, "opencv_ml230d.lib")
#pragma comment(lib, "opencv_legacy230d.lib")
#pragma comment(lib, "opencv_imgproc230d.lib")
When I built my project I got no error but when I include the <cv.h> file, unresolved external errors appear.
To solve my problem any guide may help me.
You haven added the src directory files. Look at this page: http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2010
You need to add these folders:
Source Directories... add: 'C:\OpenCV2.1\src\cv; C:\OpenCV2.1\src\cvaux; C:\OpenCV2.1\src\cxcore; C:\OpenCV2.1\src\highgui; C:\OpenCV2.1\src\ml;'
Related
I'm working on the internal mod menu for one game and I want to use CPR library inside my DLL to get the latest version of offset from the server after injection. right now I get a static version of CPR package with vcpkg and move all .lib file and include file to my project and add them in my include and lib directories and use it like this :
#pragma once
#pragma comment(lib, "crypt32.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "zlib.lib")
#pragma comment(lib, "libcurl.lib")
#pragma comment(lib, "cpr.lib")
#include "cpr/cpr.h"
cpr::Response r = cpr::Get(cpr::Url{ "https://myurl.com/getoffset" });
cout << r.status_code << endl;
cout << r.text << endl;
string json= r.text;
It's work fine without any problem but as you can see it's a bit messy with all those "#pragma comment" so I tried to use a dynamic version of CPR so after compiling it I have 3 DLL files :
myMode.dll
libcurl.dll
zlib1.dll
the problem now is I must put "zlib1.dll" and "libcurl.dll" inside game folder near .exe file otherwise it won't inject; is there any way to locate them inside my DLL and tell DLL to use that location?
or just use it like this but remove this "#pragma comment" somehow and add the location for all of them in visual studio ?
Everything you need to know about DLL search paths is well documented here.
The easiest approach would be to just statically link with libcurl and zlib instead of using the DLL stub libraries. What's the downside of that?
Otherwise, all your dependent DLLs need to be in your EXE folder, the current working directory (usually the same as the EXE folder), a system directory (no!), or the PATH.
If your extension has an installer, then maybe it just updates PATH with your install folder of your DLL and all its dependencies.
As for the "messy" pragma comment statements. The standard approach is to add these via the Visual Studio project IDE. That gives you better control of the link search path so you don't have to dump all the stub .lib files in the same folder you build from.
I created a lib file called StackExample.lib. There are functions and objects described in Stack.hpp and Example.hpp.
I want to have an easy time importing my library so I wrote another file called StackExample.hpp.
This file contains:
#pragma once
#pragma comment(lib, "StackExample.lib")
#include "Stack.hpp"
#include "Example.hpp"
Unfortunately I can no longer compile StackExample.lib because it can not import itself.
Is there a precompiler statement that I can use so that all importing programs load the lib but my lib would ignore that line?
#ifndef __STACK_EXAMPLE_INTERNAL
#pragma comment(lib, "StackExample.lib")
#endif
and then right click on your library project, select Properties => Configuration Properties => C/C++ => Preprocessor
Add __STACK_EXAMPLE_INTERNAL into "Preprocessor Definitions".
This way your library will define this definition and client's (hopefully) not.
I am trying to upgrade a Visual C++ 2008 project to a Visual C++ 2010 project. when the upgrade is finished and I compelled it, I got this error:
fatal error LNK1104: cannot open file 'mfc90d.lib'
I think it should reference to "mfc100d.lib", I tried many ways to fix it but failed.
does anyone meet the same problem?
Possible causes include
a) You are not rebuilding all source files - try deleting all output obj and lib to be sure
b) You are linking a 3rd party static lib that was built with VC9 - you will need the VC10 version
c) Your header paths are pointing at VC9 headers (check your solution's path options)
d) Your project includes an explicit reference to mfc90d for some other reason.
Next diagnosis step: set the /verbose option on the linker and work out exactly which obj is dragging in mfc90d.lib.
Martyn
I found the problem to my missing MFC100.dll by doing a global search of all my source files for the definition "_MFC_FILENAME_VER". I found following definition in one of my header files:
#define _MFC_FILENAME_VER 100
which was used in this block:
#ifdef _DEBUG
#pragma comment(lib, "mfc" _MFC_FILENAME_VER "d.lib")
#pragma comment(lib, "mfcs" _MFC_FILENAME_VER "d.lib")
#else
#pragma comment(lib, "mfc" _MFC_FILENAME_VER ".lib")
#pragma comment(lib, "mfcs" _MFC_FILENAME_VER ".lib")
#endif
I changed it to:
#define _MFC_FILENAME_VER 110
so it would compile with VS 2012's version of MFC (mfc110d.lib).
I'm using VS2010 to write some win32 app. I normally add .lib files to linkage using to project property manager. yet, sometimes, when I just want to test an API function , I don't want to modify my project file , but rather just add a removable line for linking with the required lib
What is the linker keyword for linking with a given .lib file?
You can use #pragma comment command
Example:
#pragma comment (lib, "d3d9.lib")
Another example:
#pragma comment (lib, "yourlibrary.lib")
Just put in hmm.. before int main(){}
http://support.microsoft.com/kb/153901
http://msdn.microsoft.com/en-us/library/7f0aews7%28v=vs.71%29.aspx
If there are problems:
Ignore #pragma comment(lib, ...)?
Unresolved external symbol when linking my library
I wrote an image matching tool (console application, without gui or windows), using openCV.
I want to port my EXE file to another computer but it asks for opencv dlls (opencv_core220.dll, opencv_highgui220.dll, ...)
My question is how to do it. I see two ways any of them is good:
Recompile opencv as static library (.lib instead of .dll). That didnt work. I get 10 linker errors regarding cap_vfw.obj
If possible, how to merge/embedd DLL's into exe file.
I tried to use ILMerge, but it doesnt work (Error: coul'd not load assembly from a.exe file) since it is designed for .Net only
P.S. - I am using visual studio 2005, on windows, c++ compiler, openCV 2.2
I found an answer.
You must open the original openCV project and recompile all the relevant parts in static library mode.
Do it for each project starting from libjasper and alphabetically until opencv_video. Also do the same for zlib project
For each project, go to project properties\configuration properties\general\configuration type and set it to static library
Now recompile those projects. They will create many large lib files (of up to 10MB) each. Those files are located mainly in modules directory of opencv. You must find them and copy to the directory when you keep your regular lib files when compiling against dll's. Now is a tricky part
You have to include in your code more libraries, than when you compile against dll's
Here is an example what your code should look like this. Sorry that it is not formatted well. Probably html bugs of this page:
#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;
}
The term you're looking for is static linking. "DLL" stands for "Dynamically Linked Library", which is the opposite of static. You cannot statically link a dynamically linked library. You need a "normal" library for that.
Go to the properties for the project you are building (right click on project in the solution explorer and seleck propeties). Now expand the Configuration properties->Linker option and under General, set the path to the statically linked libraries (i.e., with .lib extensions). Now select the Configuration properties->Linker->Input option and type in the names of all the libraries you want it to statically link to. Now rebuild the project and they should be linked in to the executable. It will warn you if the paths to the files are not correct.