Reputation: 1
When I run the program, I get the message:
error: abc/xyz.h: No such file or directory.
abc resides in the same directory as the C code of the program I am trying to run.
Upvotes: 0
Views: 509
Reputation: 881553
The location to find headers is an implementation-defined thing, both for the <>
and ""
variants.
So, it depends on which actual implementation you're using.
The relevant bits of C99 are from 6.10.2, "Source file inclusion" (unchanged in C11), quoted below.
A preprocessing directive of the form
# include <h-char-sequence> new-line
searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the <
and >
delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.
A preprocessing directive of the form
# include "q-char-sequence" new-line
causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the "
delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read
# include <h-char-sequence> new-line
with the identical contained sequence (including > characters, if any) from the original directive.
Many implementations will search the current directory for include files so, if your file is actually <current-directory>/abc/include/libsomething/xyz.h
, you would use:
#include "abc/include/libsomething/xyz.h"
Alternatively, you could configure the compiler to modify the search paths, such as with gcc -Iabc/include/libsomething
and just use:
#include "xyz.h"
Personally, I prefer the full specification since it makes conflicts less likely (you may have a different xyz.h
somewhere else on the include-file search path).
Upvotes: 2