1

Is it possible to add an include path on a per file basis?

I have some files (lets call them Files1) in my project that need to not include path "ABC", because of name conflicts that will occur if they do this.

Then I have some files (lets call them Files2) that should include headers from path "ABC" and I would like to add the path "ABC" to the include path of Files2, without adding it to the include path of Files1.

Is this possible or do I need to rename the conflicting header files that I want to include?

4

3 回答 3

2

I'm not aware of anything to make this possible, but if there is, there shouldn't. Rename the files and solve the conflicts. Even if such functionality existed, I would urge you not to use it.

于 2012-09-17T09:43:45.127 回答
2

One possible way around this is to put the different/conflicting versions in corresponding subfolders sharing the same parent folder, and including headers using the nested (subdirectory) path with the subdirectory being different based on which files you are working with.

That way you just add the shared parent folder to the include search path, but your different file set can do:

// files1
#include <foo/version_a/blah.h>

or

// files2
#include <foo/version_b/blah.h>

you might even be able to make a preprocessor macro (using #ifdefs or similar) that you can define so that you can switch between versions and avoid hardcoding it.

于 2012-09-17T09:48:57.767 回答
1

Yes, right-click on the desired CPP file, click Properties and under C++/General edit the Additional Include Directories appropriately.

Then left-click on another CPP file while Properties dialog is still open, and change the Additional Include Directories for it, etc...

That being said, you should properly resolve the naming conflict and not rely on include paths, if you can.

于 2012-09-17T09:58:25.713 回答