Re: Adding include directories (-I)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ian Lance Taylor wrote:
> Sebastian Biallas <sb@xxxxxxxxxxx> writes:
> 
>> My question is: Which command line switch of gcc is preferred for adding
>> include directories?
> 
> -I

Yes, I though so, too. But there is a problem with it, see below.

> 
>> And: What's the reason that -I modifies system
>> headers includes?
> 
> It doesn't.  It just changes the search path used to find header
> files.

Yes, but it modifies the search path for ""  *and*  <> includes.

This happens:

$ ls
process.h test.cc
$ cat test.cc
#include <unistd.h>
$ cat process.h
#error Wrong process.h included!
$ g++ -c -mno-cygwin -o test.o test.cc
$ g++ -c -I. -mno-cygwin -o test.o test.cc
In file included from
/usr/lib/gcc/i686-pc-mingw32/3.4.4/../../../../i686-pc-mingw32/include/unistd.h:11,
	from test.cc:1:
./process.h:1:2: #error Wrong process.h included!

[The line 11 of unistd.h reads #include <process.h>]

So, the -I. option adds '.' to the list of system header directories.
That means if I have a file which accidently has some "forbidden" name
which is used somewhere deep in the system headers, everything breaks.

I'm not sure if this is actually a (cygwin) bug or a feature, but this
certainly makes -I unusable for me...

> If you want to do something more complex, see the documentation for
> -iquote and -isystem.  They probably don't do what you want, but they
> may be instructive.

-iquote is what I want, but:

It changed syntax recently (was -I- before). So it's not (easily)
possible to write a simple makefile for use with gcc3 and gcc4. And
automake adds -I. by default.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux