Reputation: 5578
I have been trying all day to install OpenCV (versions 2.4.1 and 2.4.2) for Visual Studio 2010 on Windows 7 for C/C++.
I have been following this tutorial: http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_install/windows_install.html
I skipped installing 3rd party software (except python 2.7 and zlib from here: http://gnuwin32.sourceforge.net/packages/zlib.htm).
I run cmake, then open openCV.sln from openCV build directory, wait for visual studio to load and then build it. Visual studio gives 200 hundred errors which are just the following two repeated many times:
error C1083: Cannot open include file: 'unistd.h': No such file or directory
error LNK1104: cannot open file '....\lib\Debug\opencv_core241d.lib'
"OpenCV build directory"/bin/Release does not contain any *.exe file, just a plenty of *.pdb files, among which I can see contours.pdb. The tutorial says that I should see contours.exe there.
As there are no *.exe files, I understand that two errors I get during build are critical. I would be grateful for any ideas that could help me solve them.
Upvotes: 6
Views: 12611
Reputation: 46
I ran into some difficulty as well - the documentation is just slightly out of date.
This solution is based on this tutorial: http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2010_CMake
Here's the exact steps I took to get an opencv 2.4.2 hello world example working with Visual C++ 2010 Express:
Grab the source code
Download opencv.
Extract opencv to C:\
Building the binaries
Download cmake. Open the cmake gui..
Where is the source code: C:/opencv
Where to build the binaries: C:/opencv/build
Click Configure - for the generator choose Visual Studio 10 Click Generate.
In C:\opencv\build you should now see OpenCV.sln.
Open the solution file with VS C++ Express and build it.
Setting up the hello world project
Create a new project in VS. Choose console application and leave precompiled headers ticked. Right-click on solution file and choose properties.
In the VC++ Directories window, add the following:
Include Directories: C:\opencv\build\include;C:\opencv\build\include\opencv;C:\opencv\build\include\opencv2
Library Directories: C:\opencv\build\lib\Debug
Source Directories: C:\opencv\build\include
In C++ -> Linker -> Input, add the following to Additional Dependencies:
opencv_core242d.lib
opencv_highgui242d.lib
Hello World Content
Change the content as suggested in the tutorial to:
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int _tmain(int argc, _TCHAR* argv[])
{
IplImage *img = cvLoadImage("funny-pictures-cat-goes-pew.jpg");
cvNamedWindow("Image:",1);
cvShowImage("image:",img);
cvWaitKey();
cvDestroyWindow("Image:");
cvReleaseImage(&img);
return 0;
}
Place the image (or any image) in your project directory.
Now build and hit Debug, and it should work. Hope this helps someone.
Upvotes: 2
Reputation: 337
I can't put comment so i have to put as an answer.
@go4sri I followed what you said and compile OpenCV with visual studio 2010 but I don't know how to configure the property file and what folder to put in Library directory, include directory... I need some help.
At the moment I put :
C:\opencv\build\include in Include directory
C:\opencv\Release\lib\Debug in the Library directory. (I build into the Release folder)
But i get unresolved external symbol.
error LNK2019: unresolved external symbol "public: static class cv::MatExpr __cdecl cv::Mat::zeros(int,int,int)" (?zeros@Mat@cv@@SA?AVMatExpr@2@HHH@Z) referenced in function "public: void __thiscall CtestDlg::OnBnClickedOk(void)" (?OnBnClickedOk@CtestDlg@@QAEXXZ)
EDIT 1:
I fixed the problem by adding .lib in the input linker->input-> additional dependencies but now I have another problem. It tells me that it can't find the dll opencv_core242d.dll.
EDIT 2:
Putting all dll in the release (for release) or debug (for debug dll) resolve the problem but I don't understand why i have to do that. It can't find itself where are dlls ??
Upvotes: 1
Reputation: 1490
The following interpretation of the build steps should help you build it:
Install cmake - this is required for all platforms
cd into the extracted directory and create a new directory called release(or any other name)
From this directory, run cmake ..
You should find an OpenCV.sln file in the release directory.
Open this with Visual Stuido and run a build.
Go ahead and enjoy Opencv
Upvotes: 5