gcc include search order

Simon, Jb jb.simon@lmco.com
Thu Aug 7 04:02:00 GMT 2008


Hi.
In my unit testing I need to change some header files (target is
vxWorks, which supports some things that the sun does not). 
So, what I do is fetch the development tree, and then in a new unit test
directory I attempt to compile the unit under test. Since this is NOT
vxworks, I use sed to change some of the .h files and put them in a
./changed directory.

When I try to compile the file, it is still using the .h file from the
original location, even though I have listed the include path for
./changed before the include path for the development tree.

Here is a partial output from gcc using the -v option

GNU CPP version 3.1 (cpplib) (sparc ELF)
GNU C++ version 3.1 (sparc-sun-solaris2.8)
        compiled by GNU C version 3.1.
ignoring nonexistent directory "NONE/include"
#include "..." search starts here:
#include <...> search starts here:
 .
 changed
 /export/home4/xxx/yyyy/builds/int_rel5_latest/src/mp/interface
 /export/home4/xxx/yyyy/builds/int_rel5_latest/src/ap/app
 /export/home4/xxx/yyyy/builds/int_rel5_latest/src/shared/common
 /export/home4/xxx/yyyy/builds/int_rel5_latest/src/shared/interface
 /usr/local/include/g++-v3
 /usr/local/include/g++-v3/sparc-sun-solaris2.8
 /usr/local/include/g++-v3/backward
 /usr/local/include
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.1/include
 /usr/local/sparc-sun-solaris2.8/include
 /usr/include
End of search list.

I know the changed file is correct and that the include is not working
as expected, because when I copy the file from ./changed, back into the
development tree, the compilation works as expected.

One more bit of information. The source that I cam compiling is in
/export/home4/xxx/yyyy/builds/int_rel5_latest/src/ap/app
And it is including files from
/export/home4/xxx/yyyy/builds/int_rel5_latest/src/shared/common
These include files should be including the files from ./changed (when
they exist) but they are ignoring the .h files in the ./changed
directory and are instead using other, unchanged files in the
/export/home4/xxx/yyyy/builds/int_rel5_latest/src/shared/common
directory.

The gcc command line is something like

  TEST_DIR="."
  
  CHANGED_DIR_NAME=changed
  CHANGED_FILES_DIR=${TEST_DIR}/${CHANGED_DIR_NAME}

  CICU_HEADER_FILES="-I ${AP_INTERFACE_FILES} -I ${AP_APP_FILES} -I
${SHARED_COMMON_FILES} -I ${SHARED_INTERFACE_FILES}"
  
  HEADERS="-I ./ -I ${CHANGED_FILES_DIR} ${CICU_HEADER_FILES}"
  DEFINES="-DSUNRUN -DA10_DEBUG -DJOETEST"
  
  CFLAGS="-v -c -g -O1 -pipe -Wformat -Wunused -Wuninitialized -Wshadow
-Wmissing-prototypes -Wmissing-declarations"
  
  printf "Compiling the UUT File\n"
  gcc -fprofile-arcs -ftest-coverage ${CFLAGS} ${HEADERS} ${DEFINES}
${AP_APP_FILES}/unitUnderTest.cpp 


I hope this explanation is clear. If anyone knows how to fix the command
line so that it gets the .h files in the "changed" directory are used
instead of files in the other include directories.

Thanks
Joe

----------------------------------------------------
Time Flies like an Arrow. Fruit Flies like a Banana
 



More information about the Gcc-help mailing list