Adding include directories (-I)

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

 



Hello,

Consider the following file structure of some project:

/src
	/dir1
		file1.c
		header1.h
	/dir2
		header2.h

My question is: What is the correct/preferred way to #include
"header2.h" in file1.c?


1. Add something like -I($topdir) to the Makefile
-------------------------------------------------

This is what I usually do. That way I can write #include
"dir2/header2.h" in file1.c. This is, AFAICS, what automake does.

Now, what I just learned, the -I switch does not only modify the search
list for #include "" but also for #include <>. This was completely new
to me (what's that good for?) and yields to a problem:

I have a file called src/process.h. And now, when I include <unistd.h>
under cygwin, <unistd.h> includes <process.h> which results in inclusion
of my "process.h" which is totaly wrong at this place.

I'm not sure if the cygwin folks messed this up or if this is my fault
(don't name files process.h? Don't use -I?)

2. Add something like -I- first
-------------------------------

Uh, this sounds like a rather obscure switch. Even more, since it
changed it syntax recently to -iquote.

3. Don't use -I at all
----------------------

I could use #include "../header2.h" in file1.c. But I don't think that
this is the preferred method for this really common problem.


Thanks in advance,
Sebastian

[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