LoyalBanana
LoyalBanana

Reputation: 183

How to tell the preprocessor to search for a particular folder for header files, when I say #include <xyz.h>

I have around 120 header files (.h files) , and in all of them each one includes many other header files using #include <abcd/xyz.h>, 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 <abcd/xyz.h> as #include "abcd/xyz" , but I need to do this in all the header files wherever there is an include statement, and there are hundreds of them.

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. (<abcd/xyz.h>,<efgh/xyz.h>).

Any way to do this?

Upvotes: 2

Views: 1977

Answers (5)

sean e
sean e

Reputation: 11925

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.

Upvotes: 2

ralphtheninja
ralphtheninja

Reputation: 133128

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

Upvotes: 0

LB40
LB40

Reputation: 12341

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....

Upvotes: 0

user2189331
user2189331

Reputation:

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).

Upvotes: 0

sharptooth
sharptooth

Reputation: 170519

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.

Upvotes: 4

Related Questions