6

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.

Community
  • 1
  • 1
Jaroslaw Pawlak
  • 5,538
  • 7
  • 30
  • 57
  • 1
    unistd.h is unix header. Do you build windows version of OpenCV??? – ArtemStorozhuk Jul 17 '12 at 17:02
  • I have tried to build what I downloaded from the webpage provided in the tutorial: http://code.opencv.org/svn/opencv/tags/2.4.2 I have also tried with this: http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.2/OpenCV-2.4.2.exe/download but cmake shows "CMakeList.txt missing" error – Jaroslaw Pawlak Jul 17 '12 at 21:12

3 Answers3

5

The following interpretation of the build steps should help you build it:

  1. Install cmake - this is required for all platforms

  2. cd into the extracted directory and create a new directory called release(or any other name)

  3. From this directory, run cmake ..

  4. You should find an OpenCV.sln file in the release directory.

  5. Open this with Visual Stuido and run a build.

  6. Go ahead and enjoy Opencv

go4sri
  • 1,490
  • 2
  • 15
  • 29
  • I had problems with step 3: cmake was showing that CMakeList.txt is missing, but I have just tried it again and it worked. **I think the problem could be that I did not restart cmake** and it cached something from the other sources I tried. Thanks a lot! – Jaroslaw Pawlak Jul 18 '12 at 09:23
2

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.

1

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 ??

Seltymar
  • 337
  • 6
  • 21
  • You are linking dymamically. To pickup dlls, you will need to add the directory to your path: `MyComputer->Advanced System Settings->Environment Variables. Edit PATH` and add the folder containing your Dlls. Restart the command window/app/visual studio and you should be good to go. Note: if you want both release and debug DLLs, you will need to add both to PATH. On a different note: Putting @go4sri in an answer does **NOT** notify me - It works only in comments :) – go4sri Jul 19 '12 at 05:05
  • @go4sri I enter the path (release and debug) to the environment Variables as you said. In both for the current user and the system but it still doesn't see the dll. Is there anything to configure in visual studio ? PS: I don't know how to notify in "answer". I think I can't and I don't have enough point to put comment... not yet ^^. – Seltymar Jul 19 '12 at 07:15
  • Also I know that my Environment Variables work because I can access to directories using the shell. – Seltymar Jul 19 '12 at 07:31
  • What is the value of your path variable? (You can show it using `echo %PATH%`) – go4sri Jul 20 '12 at 04:20
  • @go4sri `echo %OPENCV_DIRDB%` gives me `C:\opencv\Release\bin\Debug\ ` . – Seltymar Jul 20 '12 at 07:38
  • Actually it is `C:\opencv\Release\bin\Debug` I add the "\" by mistake. – Seltymar Jul 20 '12 at 07:47
  • 1
    you have to set `PATH` to `C:\opencv\Release\bin\Debug`. not `OPENCV_DIRDB` – go4sri Jul 20 '12 at 10:25