Reading the fine print of the -I
switch in GCC, I\'m rather shocked to find that using it on the command line overrides system includes. From the preprocessor docs
Looking back at the GCC manuals it looks like -iquote
and other options were only added in GCC 4: https://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Directory-Options.html#Directory%20Options
So the use of "-I"
is probably some combination of: habit, lazyness, backwards compatibility, ignorance of the new options, compatibility with other compilers.
The solution is to "namespace" your header files by putting them in sub directories. For example put your endian header in "include/mylib/endian.h"
then add "-Iinclude"
to the command line and you can #include "mylib/endian.h"
which shouldn't conflict with other libraries or system libraries.