views:

126

answers:

2

I have installed Microsoft Visual C++ Express Edition, Version 9.0.30729.1 SP. The command line compiler that comes with it is at Version 15.00.30729.01 for 80x86. I have installed OpenCV 20.0a.

I want to compile the following program:

#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;
}

The thing is, I do NOT want to use the "visual" aspect of Visual C++, I want to use the command line compiler which is "cl.exe".

When I try to compile this program, I get the error:

C:\visualcpp>cl OpenCV_Helloworld.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86 Copyright (C) Microsoft Corporation.  All rights reserved.

OpenCV_Helloworld.cpp
OpenCV_Helloworld.cpp(6) : fatal error C1083: Cannot open include file: 'cv.h': No such file or directory

So I tried to specifiy with /I like this

C:\visualcpp>cl /I "C:\OpenCV2.0\src\cv" OpenCV_Helloworld.cpp

And variations thereof, in the hope that /I would somehow tell cl.exe where cv.h is, but I get the same error.

As a side note, I don't know if that's related but I noticed that there is no file "cv.h" in "C:\OpenCV2.0\src\", but rather a file called "_cv.h"! So I changed the header accordingly, but still.

I think I'm able to program in C++ somewhat but I don't understand how to specify header / linker file locations, especially with cl.exe as I have only used gcc before and I don't think I know what I'm doing right now. Please help me to compile this! I want to get started in OpenCV.

A: 

There is no visual aspect of Visual Studio. It's just a name. All C++ programs are compiled with cl.exe. The C++ compiler has no knowledge of any visual anything - it's just a brand. cl.exe can only be invoked from within Visual Studio, however. It is not a command line compiler.

DeadMG
Where did you get the idea that cl can only be invoked from within Visual Studio - that is pretty much just plain wrong. cl can of course be invoked from the command line, for example when used in makefiles, jam files, via SCons etc., or other build environments.
Jim Brissom
http://msdn.microsoft.com/en-us/library/ms235639(VS.80).aspx - What's that, can't use the regular command line?
DeadMG
+1  A: 

First of all, be sure to set up the environment by calling one of the batch files that come with Visual Studio, i.e. vsvars32.bat found in your Visual Studio folder under Common7\Tools. During installation, there is usually also a start menu entry created which opens a console and executes the setup script. This will make sure environment variables are set up properly and the compiler and linker has access to header files, libraries, tools are on your path etc.

You will find the cl command line options listed here for documentation: Compiler Command-Line Syntax

As for OpenCV: Take a look at the directory structure of OpenCV. It's

OpenCVRootFolder\include\opencv\cv.h

so you would usually go ahead and say:

cl /I"X:\OpenCVRootFolder\include" [...] source.cpp /LINK [...]

and in your code, include the cv header via:

#include <opencv\cv.h>

...or you could just go ahead and do

cl /I"X:\OpenCVRootFolder\include\opencv" [...] source.cpp /LINK [...]

and simple include

#include <cv.h>

I don't see why you wouldn't want to use Visual Studio, though. It's just an IDE, there are no features forced upon you or included if you don't want them to.

Jim Brissom