Adding include directories (-I)

Sebastian Biallas sb@biallas.net
Wed Feb 28 15:18:00 GMT 2007


John Love-Jensen wrote:
> Hi Sebastian,
> 
> You question is not a GCC specific question, it's more of a Lakos'
> Large-Scale C++ Software Design question, and is off-topic for this forum.

Maybe my question wasn't clear:

My question is: Which command line switch of gcc is preferred for adding
include directories? And: What's the reason that -I modifies system
headers includes?

> BarGizmo.cpp might have:
> #include "Bar/BarGizmo.h" // Self
> #include "BarGizmoImpl.h" // PImpl pattern
> #include "Foo/FooWidget.h"

So, how does the Makefile look like, so that gcc finds Foo/FooWidget.h?

How do you avoid that -I. overrides system headers?

> BTW, regarding Makefile, please read "Recursive Make Considered Harmful"
> <http://members.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html>.  You
> may want to consider using "makefile fragments" instead of recursive make --
> which would be yet-another-disciplined-convention.

That's for the pointer, I'll read it.

But my question is a little bit more general: There are existing
projects, which are based on recursive make and automake. They use
things like -I. by default, which results (as I mentioned) in obscure
bugs if your files happen to have some "reserved" name -- in my case
process.h. I guess you can't know in advance which file names are
actually reserved if you want your project to be portable.

So, are all these projects that use -I. and -I($topdir) by default
misdesigned? I guess I'm missing an important point here, therefore my
question.

Thanks,
Sebastian



More information about the Gcc-help mailing list