none
fatal error C1083: Cannot open include file: 'cv.h' and include file: 'stdafx.h'

    Question

  • i m a new user of microsoft visual studio c++ express edition 2008.whenever i want to build and run a simple program like this..........
     / ex1.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include <iostream>

    int _tmain(int argc, _TCHAR* argv[])
    {
       std::cout << "Hello World" << std::endl;
       return 0;
    }
    there is an error like .........
    c:\documents and settings\disha\my documents\visual studio 2008\projects\box\box\box.cpp(4) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
    Build log was saved at "file://c:\Documents and Settings\ratri\My Documents\Visual Studio 2008\Projects\box\box\Debug\BuildLog.htm"
    box - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    then when i configure it to use open cv 2.0 and try a sample program like......
    #include <cv.h>
    #include <highgui.h>

    /*
        This will pop up a small box with "Hello World" as the text.
        @author: Gavin Page, gsp8334@cs.rit.edu
        @date: 28 November 2005
    */
    int main( int argc, char** argv ) {
        //declare for the height and width of the image
        int height = 320;
        int width = 240;
        //specify the point to place the text
        CvPoint pt = cvPoint( height/4, width/2 );
        //Create an 8 bit, 3 plane image
        IplImage* hw = cvCreateImage(cvSize(height, width), 8, 3);
        //initialize the font
        CvFont font;
        cvInitFont( &font, CV_FONT_HERSHEY_COMPLEX,
            1.0, 1.0, 0, 1, CV_AA);
        //place the text on the image using the font
        cvPutText(hw, "Hello World", pt, &font, CV_RGB(150, 0, 0) );
        //create the window container
        cvNamedWindow("Hello World", 0);
        //display the image in the container
        cvShowImage("Hello World", hw);
        //hold the output windows
        cvWaitKey(0);
        return 0;
    }
    then the error occurs again when i try to build it,such as
    ------ Build started: Project: test1, Configuration: Debug Win32 ------
    Compiling...
    test1cfile.cpp
    e:\test\test1\test1\test1\test1cfile.cpp(1) : fatal error C1083: Cannot open include file: 'cv.h': No such file or directory
    Build log was saved at "file://e:\test\test1\test1\test1\Debug\BuildLog.htm"
    test1 - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    for this program i configure 2008 express as

    Project

    Open Visual Studio

    New -> Project -> Win32 Console Application

    Include directories

    In the project’s settings, Configuration Properties -> C/C++ -> General -> Additional Include Directories add

                C:\Program Files\OpenCV\cv\include\

                C:\Program Files\OpenCV\cxcore\include\

                C:\Program Files\OpenCV\cvaux\include\

                C:\Program Files\OpenCV\otherlibs\highgui\


    Library files

    In Configuration Properties -> Linker -> Input -> Additional Dependencies add

     

    "C:\Program Files\OpenCV\lib\cv.lib“
    "C:\Program Files\OpenCV\lib\cvaux.lib“

    "C:\Program Files\OpenCV\lib\cxcore.lib“

    "C:\Program Files\OpenCV\lib\cvcam.lib“

    "C:\Program Files\OpenCV\lib\highgui.lib"
    i'v already checked the correct paths,the location of the folders which are mentioned in the paths,but the error appears again and again.plz help me.i want to know the exact reason,because i've done everything i could.please,please someone helps me.
    • Edited by ratri Sunday, January 03, 2010 7:12 PM
    Sunday, January 03, 2010 7:08 PM

Answers

  • If Empty Project checkbox is selected, Wizard doesn't create stdafx.h header and you cannot include it.
    In this case, you need to create Main.cpp and put your code with #include <cv.h> and #include <highgui.h> in it.

    Or create project with unchecked Empty Project option and look what Wizard will create for you. Put #include <cv.h> and #include <highgui.h> in stdafx.h.

    Also, you can use Alt+F7 in VS > Configuration Properties > C/C++ > Precompiled Headers to see difference in these projects. David already gave you a link to info about Precompiled Headers.
    • Proposed as answer by Nikita Leontiev Thursday, January 07, 2010 10:09 AM
    • Marked as answer by Wesley Yao Friday, January 08, 2010 3:33 AM
    Wednesday, January 06, 2010 10:38 AM

All replies

  • Is the stdafx.h header exists in your project? It is standard header that VS wizard generates.
    Sunday, January 03, 2010 7:10 PM
  • About cv.h: have you checked this file in C:\Program Files\OpenCV\include folder? :-)
    By the way, by defaults OpenCV creates it's directory in the root.
    Sunday, January 03, 2010 7:25 PM
  • yes. stdafx.h header exists in my project.in spite of this, errors happen.
    Sunday, January 03, 2010 7:25 PM
  • So, you mean that if you create Win32 Console Application by VS wizard, when you compile it, you receive "Cannot open include file: 'stdafx.h'" error?
    Sunday, January 03, 2010 7:30 PM
  • yes. stdafx.h header exists in my project.in spite of this, errors happen.

    Where is it?

    And does your project have precompiled headers set in

    Project Properties->Configuration Properties->C/C++->Precompiled Headers

    ?

    David Wilkinson | Visual C++ MVP
    Sunday, January 03, 2010 7:34 PM
  • yes that's true.

    Monday, January 04, 2010 3:29 AM
  • it is in 1st program after the line-" / ex1.cpp : Defines the entry point for the console application." no,my project does not have precompiled headers set in.if it is needed,then would you kindly tell me,what is it? and how can i use it? please help me.
    Monday, January 04, 2010 3:46 AM
  • it is in 1st program after the line-" / ex1.cpp : Defines the entry point for the console application." no,my project does not have precompiled headers set in.if it is needed,then would you kindly tell me,what is it? and how can i use it? please help me.

    Actually, I was asking where in the file system it is?

    You can read about precompiled headers here:

    http://msdn.microsoft.com/en-us/library/szfdksca.aspx

    But I think it will be easier if you just start over:

    Create a new Win32 console application. By default it should have precompiled headers enabled, and it should have files stdafx.h and stdafx.cpp in the project directory. Before you do anything, try to compile it.

    Do you get the errors now?





    David Wilkinson | Visual C++ MVP
    Monday, January 04, 2010 11:33 AM
  • That's exactly what I was asking in my previous post :-)
    Monday, January 04, 2010 11:55 AM
  • I have already created new Win32 console application wizard.I make it an "Empty Project"by selecting the box under "Application Setting".i try all of  these,but all is in vain.errors come again and again.Please help. 
    Wednesday, January 06, 2010 8:13 AM
  • If Empty Project checkbox is selected, Wizard doesn't create stdafx.h header and you cannot include it.
    In this case, you need to create Main.cpp and put your code with #include <cv.h> and #include <highgui.h> in it.

    Or create project with unchecked Empty Project option and look what Wizard will create for you. Put #include <cv.h> and #include <highgui.h> in stdafx.h.

    Also, you can use Alt+F7 in VS > Configuration Properties > C/C++ > Precompiled Headers to see difference in these projects. David already gave you a link to info about Precompiled Headers.
    • Proposed as answer by Nikita Leontiev Thursday, January 07, 2010 10:09 AM
    • Marked as answer by Wesley Yao Friday, January 08, 2010 3:33 AM
    Wednesday, January 06, 2010 10:38 AM
  • Lot of thanks.Thank you for your solution.But one problem still arises.Building the program is ok.But when I'm running the program by pressing "F5",on the output window I'm seeing these type of message- 'helloppt.exe': Loaded 'C:\Documents and Settings\Ratri\My Documents\Visual Studio 2008\Projects\helloppt\Debug\helloppt.exe', Symbols loaded. 'helloppt.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll' 'helloppt.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll' 'helloppt.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_f863c71f\msvcr90d.dll' 'helloppt.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_f863c71f\msvcp90d.dll' The program '[3332] helloppt.exe: Native' has exited with code 0 (0x0). and the Visual studio 2008 command promt or the .exe output file once suddenly appears and at that time disappears also.Output is not stable.I can't see the output result because it disappears so quickly.Could you kindly tell me the the reason?
    Thursday, January 07, 2010 4:41 AM
  • Try running with Ctrl-F5.

    Or add a line at the end of your program before the final return such as:

    system("pause"); // include <stdlib.h>

    - Wayne

    Thursday, January 07, 2010 5:03 AM
  •  Hello,thank you for giving me a such a helpful solution. My first sample program is running.
    but when I configure microsoft visual studio c++ express edition 2008 to use open cv 2.0 and try a sample program like......
    #include <cv.h>
    #include <highgui.h>

    /*
        This will pop up a small box with "Hello World" as the text.
        @author: Gavin Page, gsp8334@cs.rit.edu
        @date: 28 November 2005
    */
    int main( int argc, char** argv ) {
        //declare for the height and width of the image
        int height = 320;
        int width = 240;
        //specify the point to place the text
        CvPoint pt = cvPoint( height/4, width/2 );
        //Create an 8 bit, 3 plane image
        IplImage* hw = cvCreateImage(cvSize(height, width), 8, 3);
        //initialize the font
        CvFont font;
        cvInitFont( &font, CV_FONT_HERSHEY_COMPLEX,
            1.0, 1.0, 0, 1, CV_AA);
        //place the text on the image using the font
        cvPutText(hw, "Hello World", pt, &font, CV_RGB(150, 0, 0) );
        //create the window container
        cvNamedWindow("Hello World", 0);
        //display the image in the container
        cvShowImage("Hello World", hw);
        //hold the output windows
        cvWaitKey(0);
        return 0;
    }
    then the error occurs again when i try to build it,such as
    ----- Build started: Project: helloworld, Configuration: Debug Win32 ------
    Compiling...
    stdafx.cpp
    Compiling...
    hellowordtest.cpp
    c:\documents and settings\ratri\my documents\visual studio 2008\projects\helloworld\helloworld\hellowordtest.cpp(2) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
    helloworld.cpp
    c:\documents and settings\ratri\my documents\visual studio 2008\projects\helloworld\helloworld\helloworld.cpp(5) : fatal error C1083: Cannot open include file: 'cv.h': No such file or directory
    Generating Code...
    Build log was saved at "file://c:\Documents and Settings\ratri\My Documents\Visual Studio 2008\Projects\helloworld\helloworld\Debug\BuildLog.htm"
    helloworld - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    When i creat this sample program I use

    New -> Project -> Win32 Console Application

     I create project with unchecked Empty Project option
    include directories

    In the project’s settings, Configuration Properties -> C/C++ -> General -> Additional Include Directories add

               C:\Program Files\OpenCV2.0\include\opencv\cvaux\

                C:\Program Files\OpenCV2.0\include\opencv\cv\

               C:\Program Files\OpenCV2.0\include\opencv\cxcore\

               C:\Program Files\OpenCV2.0\include\opencv\highgui\

               C:\Program Files\OpenCV2.0\include\opencv\cvcam\
    I'v already checked the correct paths,the location of the folders which are mentioned in these paths,

    Library files

    In Configuration Properties -> Linker -> Input -> Additional Dependencies add

     

    "C:\Program Files\OpenCV\lib\cv.lib“
    "C:\Program Files\OpenCV\lib\cvaux.lib“

    "C:\Program Files\OpenCV\lib\cxcore.lib“

    "C:\Program Files\OpenCV\lib\cvcam.lib“

    "C:\Program Files\OpenCV\lib\highgui.lib"

    But I'm not sure about these paths.Because In openCv2.0 folder I can't get the library files.
    Can I run this sample program in microsoft visual studio c++ express edition 2008 environment at all?
    If so,then What is correct paths for open cv2.0 library files?
    Why the errors come again and again?
    Am I right about including Library and header file?
    Please help .


    Saturday, January 09, 2010 8:41 AM
  • 1) Create new project (not Empty project, leave Precompiled Headers checkbox checked).

    2) Go Tools menu > Options > Projects and Solutions > VC++ Directories.
    Select "Include files" in "Show directories list". Click New Line button and provide path to OpenCV include folder ("C:\Program Files\OpenCV2.0\include", cv.h file should exist in this folder).
    Select "Library files" in "Show directories list". Click New Line button and provide path to OpenCV library folder ("C:\Program Files\OpenCV2.0\lib", cv.lib file should exist in this folder).

    3) Open stdafx.h file in your project and add #include <cv.h> #include <highgui.h> lines into it after other included headers.

    4) Open <your project name>.cpp. Copy code from sample main function to your _tmain function.

    5) Run app.
    Saturday, January 09, 2010 10:28 AM
  • excuse me..i have the same problem and i need  help urgently...how could you solve it?can you explain...
    Friday, March 19, 2010 3:59 AM
  • This question was answered. Read my previouse post from these topic for solution.

    Or create new thread and describe your problem in it.

    Friday, March 19, 2010 9:50 AM
  • Hi,I'm dealing with visual studio for a few days.I'm getting some problem when i started installing it.When i install Microsoft visual studio6.0(Enterprise edition)first time,for some reason (suddenly computer UPS breakdown)1st CD setup is stopped between installing period.So when I restart my computer,i see in the control panel there is no longer such a program(visual studio6.0).In the start menu "all programs" option, there is no such thing.But in the "program files" there is a visual studio folder.So I delete this folder using "Shift+Delete" key to start a new installation.But the problem is my disk space is getting low.Because the actual size of "program files" folder is differ from the size on disk.I think some files are not be removed fully.But i already search for this folder,there is no existence.Can u tell me why this problem is happened?Why the actual size and sine on the disk of the "program files" folder is differ?Please help me.because i cannot install the visual studio either.
    Wednesday, April 07, 2010 1:35 PM
  • Remove all unnecessary programs from your PC. Clean temp folders. Or maybe buy new HDD =)

    And if you don't need MFC try to use Visual C++ 2008 Express. It is free.


    Nikita Leontiev
    Thursday, April 08, 2010 4:02 PM