CPATH versus -I

Dan Ports dports at macports.org
Thu Jun 17 21:22:57 PDT 2010


On Thu, Jun 17, 2010 at 10:46:55PM -0400, Michael Dickens wrote:
> When should I be
> using CPATH=<PATH:LIST> versus "-I<PATH_1> -I<PATH_2> -I..."?  Is there
> any difference between them, maybe search order?  When is one preferable
> to the other?  Is their interpretation compiler dependent?

CPATH is searched after -I options provided on the command line, but
before -isystem options. There's also C_INCLUDE_PATH, which is searched
after -isystem directories.

It makes sense to use one of these options (CPATH, C_INCLUDE_PATH, or
-isystem) instead of -I to add $prefix/include, since they're searched
after any -I flags the program specifies. This keeps the program's
include files from being shadowed by identically-named files in
$prefix/include.

I think this is probably the cause of at least some of qt4-mac's build
conflicts. With libevent active, it sounds as though something is doing
a #include <Event.h> and getting libevent's /opt/local/include/event.h
instead.

I see that by default base both sets CPATH and adds -I flags to CFLAGS.
Not sure why we do that. It seems like the right thing to do would be
to rely on CPATH alone, or change -I to -isystem. Is there a reason not
to do this? (I found a couple of old messages suggesting this, but not
much discussion.)

Dan

-- 
Dan R. K. Ports              MIT CSAIL                http://drkp.net/


More information about the macports-dev mailing list