This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Search Path for #include Files

Hi,


Would anyone be able to give more clarity on the following statement found in section 2.5.2 of SPRU514E and other TI compiler documentation.

1. The directory of the file that contains the #include directive and in the directories of any files that
contain that file.

This is a rule followed by the compiler when searching for #include files enclosed by (" "). An example would be great!


Many thanks,


Adam

  • Let's start with a simple example ...

    // base.c
    #include "near_by.h"
    ...
    

    Where does the compiler look for the file near_by.h?  It looks in the directory where base.c resides.  If you are building a CCS project, this will almost always be the project directory.  

    Now, let's add to that example to make it more interesting.  First, show one more line from base.c ...

    // base.c
    #include "near_by.h"
    #include "path/to/far_away.h"
    ...

    And let's say that far_away.h has this ...

    // far_away.h
    #include "even_farther.h"
    ...

    How is the full directory path to faraway.h formed?  Concatenate the directory which contains base.c with "path/to".  That's an obvious extension to the existing method.

    Here is the interesting question: Where does the compiler look for even_farther.h?  There are two reasonable choices:  The directory where far_away.h resides, or the directory where base.c resides.  The TI compiler looks in the directory where far_away.h resides, and only there.  It never looks in the directory where base.c resides.  Other compilers may do this differently.  The standards for C and C++ do not specify this behavior.

    For more background on how header files are found, with emphasis on the difference between "this.h" and <that.h>, please check out this video .

    Thanks and regards,

    -George

  • Hi George,

    Thanks for your reply. The last two parts clear up my confusion over the wording.

    Kind regards,

    Adam

  • George Mock , wonderful explanation, 10 out of 10. Thanks.