Restrict header file inclusion

Hi,

I have one requirement. I have a project lets Say baseProject.vcxproj. It has some header files. Another project lets say dependentProject.vcxproj loads baseProjects's dll and uses some of its header files.

When some other project lets say unrelatedProejct includes the header file from e dependentproject which includes baseproject's header file. It makes to change the include driectory setting of unrelatedproject.

Any idea to avoid this.?

1
2
3
4
5
baseproject

base.h
{
}


1
2
3
4
5
6
7
dependentProject

dependent.h

{
#include "base.h"
}


1
2
3
4
5
6
7
8
9
unrelatedProject

some.h or some.cpp

{
#include "dependent.h"

//In this case it will include base.h also and needs to change it's include direcotries settings.
}



Thanks,
Anns.
How do you expect unrelatedProject to see the class definitions in base.h without including base.h?
Since dependent.h includes base.h, in UnrelatedProject if we include dependent.h base.h also visible right?
I'm not sure what you mean by "visible". If a file in UnrelatedProject includes dependent.h, then it will also need to include base.h. UnrelatedProject therefore needs to know where to find base.h .
Hi yeah i got that. Many projects includes dependent.h so do we need to change the include directory settings for all projects?

No other option?
You could treat baseproject as a separate component that is installed to a standard location. Have the header files installed to a common includes directory, e.g. C:\MySoftware\include - or, more sensibly, to a subdirectory of that standard directory named, e.g., "baseproject".

Then make all your projects have "C:\MySoftware\includes" in their include path.

You'll have to make sure that your include statements qualify the header file with the subdirectory:

#include "baseproject/base.h"

This means you'll only have to alter your projects once, to add C:\MySoftware\include to the path. Then, if you need to add other dependencies, you won't need to modify the settings over and over again - just add new subdirectories to the common include directory, and ensure those subdirectories are used to qualify the include statements.

Alternatively, if you're using MSVC, you can use Property Sheets. Have a single sheet that specifies all the header directories you need. Then have all your projects inherit the same Property Sheet. Then, in future, if you need to add more dependencies to all projects, you just update the single Property Sheet, so that all projects automatically inherit the new setting.

Note that, if you're including headers from baseproject, then you'll probably need to link against the libraries from baseproject too. You'll need to do something analogous to the above with library files and paths.
No. This is what the compiler's search paths are for.

As part of your compile, tell the compiler where to find the non-standard files (the ones to the base project your project depends on).
Topic archived. No new replies allowed.