views:

42

answers:

4

I have a project, and I added all the source files to it. I then clicked build, and it said:

fatal error C1083: Cannot open include file: 'common.h': No such file or directory 1> crc64_tablegen.c

This is rather annoying, because common.h is in my project! It's right there! I think it might be in a different directory though. Is the the reason? Should I move everything to a root directory, then add that instead? Thanx!

+1  A: 

Where files are in the project structure makes no difference to the compiler when it is attempting to open include files. If they are in a different directory, you will need to path them appropriately.

That is, if you have this directory structure:

project/include/common.h
project/src/main.cpp

And you have this in your project:

Project
|-> common.h
|-> main.cpp

Your main file will need to do this:

#include "../include/common.h"

And not this:

#include "common.h"

You may, alternatively, define project/include as an Additional Include Directory in your project settings. This will allow you do use the second include form shown above.

jdmichal
A: 

Compiler doesn't know anything about project and files included in it. If .h file is in another directory, you need to add this directory to the list. For example, open Project - Properties - C++ - General - Additional Include Directories, and add $(ProjectDir)Include or something like this.

Alex Farber
A: 

In VC++, the location of files within the project is virtual and has no link whatsoever to the actual filepaths. You may have to be more specific with #include and/or move the source files into the project directory to be found.

DeadMG
+1  A: 

Try and add the path in the project settings under Additional Include Directories.

Here are the full set of steps:

  1. Drop down the Tools menu, and select Options
  2. In the box on the left is a list of option categories. Select "Projects and Solutions" and then the sub-category "VC++ Directories"
  3. In the upper right hand corner is a drop-down box that selects a particular set of default directories, including "Executable files", "Include files", "Reference files", "Library files", and "Source files". Generally, you only want to add to the "Include files" or "Library files" lists. Select "Include files"
  4. In the middle of the right hand side of the window is a list of directories. Add the include path by pressing the "New Line" button above the window, or by pressing "Ctrl-Insert". A blank entry appears for you to either type the path or navigate by clicking the "..." button. Generally the final path you want will end with a folder called "include". Enter the path now.
  5. You're done, click OK
Faisal Feroz