Thread: Can't find Header File!

  1. #1
    Registered User
    Join Date
    Apr 2002

    Unhappy Can't find Header File!

    I'm brand new to C++ (2+ weeks reading Deitel and Horton) using Visual C++ 6 compiler , and can't for the life of me get my header file appended to my .cpp pgm. I added header file Box.h to header file directory in workspace and try reading it in using
    #include "box.h" just before int main() in .cpp pgm ... but keep getting error on compile:
    fatal error C1083: Cannot open include file: 'Box.h': No such file or directory
    I welcome any suggestions .. thanks to all.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Northern Virginia/Washington DC Metropolitan Area
    Your header file should physically exist in the same directory as the cpp file if you are trying to include it using #include "Box.H". If you've done that, you shouldn't need to even go through the Project->AddFiles menu commands to add a header file to your project. What do you mean by header file directory? As an example, if you have a workspace titled "MyWorkSpace" and a project titled "MyProject", you should most likely have the following directory structure to begin with:


    In this directory should be your cpp and header file.

    If your header file exists in another directory somewhere you will need to remove if from within the project window (go to the header files folder and highlight the file and press the 'delete' key), then go open up an explorer window and physically move (i.e. cut and paste) the file into the same directory where you cpp file exists. Then, as long as you are including the header file in your cpp source file, it will automatically be added to the projects "header files" folder once you build the project.

    The "header files" folder in the project window is not a physical area on the hard disk, it is just there to make it easy for you to see what header and source files are associated with your project. If your header file was in a different place physically from your source file but you had added the header file to the project using the Project->Add Files menu option, then the build will still fail because the #include "Box.H" preprocessor directive will attempt to find and open a "Box.H" file in the same location as the source file.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Apr 2002
    ...thanks a lot for your time .. still seem to be knocking my head against the wall .... by 'header file directory - I should have said
    'header file folder' displayed in the workspace area..
    My header file is put in this folder when I added it to the project, but as you pointed out that's not the physical location just a convenient Microsoft display.. I checked Explorer and I do see the header file Box.h
    C Header File
    in there with other files that have the name of the project and
    .dep .mak and .dsp extensions. I did not see my source code
    with it's .cpp extension. Does my header file sound like it's in the right place.. Thanks in advance for your input. HowardS

  4. #4
    With MSVC++...

    1. create new header file
    2. save it...
    3. build

    You can check to see if a header file is in your current direc or not by compiling it. It will tell you if it's in your project. Add it to your proj if it's not.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Also, make sure that when you include the header in the cpp file that it is the correct case.

    #include "Box.h"


    #include "box.h"

    are different.

    If it is not in your project, just right-click the header file folder on your file viewer and click add files, and select it.

  6. #6
    Registered User
    Join Date
    Apr 2002
    I started from scratch as per 'unregistered' suggested and finally got the header file to be found and working. I probably somehow kept running a version of Box.h that was corrupted. Sometimes its' best to just begin over .. solution was saving Box.h as Box2.h, and changing #include "box.h" to #include "box2.h" , clicking on Project...Add to project...then files.. then running Build and the program (from pg.293 of Horton's 'Beginning Visual C++') did work. I changed the book's program to use a header file to include the Class definition, a constructor function, default function and member function. Thanks a lot to 'unregistered' for direction and
    'hk_mp5kpdw'. and Mr. Wizard for also taking time to enlighten.
    Regards HowardS.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  2. Need help understanding Header Files
    By Kaidao in forum C++ Programming
    Replies: 11
    Last Post: 03-25-2008, 10:02 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Where to find the code for Header File FUnctions
    By vsriharsha in forum C Programming
    Replies: 1
    Last Post: 04-02-2002, 12:37 PM
  5. Replies: 6
    Last Post: 04-02-2002, 05:46 AM