On a Linux system, does gcc recursively search the path declared in CPATH environment variable, or do I need to specify every Includes sub-directory explicitly?
1 Answers
3
votes
CPATH specifies the list of directories to search. The compiler searches exactly those directories, not any sub-directories (so no recursive searching). That is, given a name from #include "somedir/header.h", it will look in the directories specified via -I and -isystem and specified via CPATH and will add /somedir/header.h to each of those entries — and that's all.
This is reasonable. If it did recursive searching, you'd have to worry about getting the order right for files such as <time.h> (because there's also <sys/time.h> and it might be found by a recursive search).