4

My development environment is such that I have some_header.h in /usr/include and in /another/directory. /another/directory contains some header files I need to include in my program, but I want to use some_header.h from /usr/include. When I use

 gcc ... -I/another/directory

gcc uses /another/directory/some_header.h. If I use

 gcc ... -I/usr/include -I/another/directory

gcc does the same thing because it ignores /usr/include since it is part of the standard search path, but it gets searched after non standard directories included with -I.

Any ideas?

bdonlan
  • 224,562
  • 31
  • 268
  • 324
Dan Hook
  • 6,769
  • 7
  • 35
  • 52

3 Answers3

8

Use the -iquote switch:

Include the files that are in another/directory using quotes:

#include "another_file.h"

Then use

gcc -iquote /another/include ...

to add a search path for quoted include files. This switch will add a directory that is searched for quoted include files after the current directory and before -I and system include paths.

Include your other include files using brackets (i.e. #include <header.h>).

See here for more information: Where are include files stored - Ubuntu Linux, GCC

Community
  • 1
  • 1
Karl Voigtland
  • 7,637
  • 34
  • 29
  • This seemed so close to working, but it turns out that the files in /another/directory use #include so they couldn't find their include files when I used -iquote. – Dan Hook Aug 07 '09 at 14:02
  • 1
    Hmm, thats odd. The preprocessor should still search for in the -I and system include paths. Seems to work for me. – Karl Voigtland Aug 07 '09 at 14:12
5

Have you looked at -nostdinc ?

The manual says:

-nostdinc
Do not search the standard system directories for header files. Only the directories you have specified with -I options (and the directory of the current file, if appropriate) are searched.

Of course that means that you will have to specify anything that normally goes on the standard search path that you do want...

dmckee --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
0

Have you tried unsetting the system INCLUDE path environment variable?

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
  • Well, it's empty, but that doesn't matter. gcc automatically looks in certain directories, irrespective of environment variables. http://gcc.gnu.org/onlinedocs/gcc-4.1.1/cpp/Search-Path.html#Search-Path – Dan Hook Aug 06 '09 at 19:19