views:

230

answers:

5

I have around 120 header files(.h files) , and in all of them each one includes many other header files using #include , but as I kept .h files in a specific folder, preprocessor is generating filenotfound error.

I moved all the .h files to the single .C file that is calling the first headerfile.

One way to do is make #include as #include "abcd/xyz" , but I need to do this in all the header files where ever there is an include statement, and there are hundreds of them.

and I can't include many of them in the headerfiles section in Visualstudio because , some of the headerfiles have the same name, but they reside in different directories.(,).

anyway to do this ?,

+3  A: 

You should add a path into "Additional include directories" in the "C++" section of the project options (the "General" tab). You can use environment variables as well as "this folder" (.) shortcut and "up one folder" (..) shortcut for this setting to not be bound to a certain directory structure.

sharptooth
A: 

In the project settings (under C/C++ in VS2005/2008) there's an option for "additional include directories". You can add the folders containing your header files here, using relative paths.

You can also do this at the IDE level in Tools -> Options -> Projects and Solutions -> VC++ Directories -> Include Files. Typically this method is reserved for headers included as part of a formal library. The first option is typically preferred as it's portable (you can ship your project file to another developer and, provided you use relative/macro'd paths, they can build the project as-is).

James D
A: 

What you're looking for is the -I flag and you give the directory... If you have a Makefile, you should add it to the CPP_FLAGS something like that....

LB
A: 

You can also add an INCLUDE variable to your environment variables.

Magnus Skog
+1  A: 

and I can't include many of them in the headerfiles section in Visualstudio because , some of the headerfiles have the same name, but they reside in different directories.(,)

That's a pretty big problem unless the files that are including those non-uniquely named headers are in the same directory as the header files themselves.

You have no way to guarantee that the compiler will locate one header before another without modifying the #include directive itself (and adding a relative path as one example).

EDIT: It looks like Visual Studio will allow you to specify different Additional Include Directories for each source file in a project (rt-click on the source file in Solution Explorer and modify C/C++ properties). But I think this would be more work than modifying the #include directives themselves - depends on how many non-unique header filenames you have.

sean e