How to properly alias a /usr/include header file for inclusion as <foo.h>?

  aliasing, c++, c++11

Suppose I’ve written a header named foo.h, and that foo.h is also the name of one of the headers under /usr/include. Now, in my source files, I want to say #include <foo.h>, but arrange my build so that the compiler will search the directory with my foo.h before /usr/include. Note: I realize this is a bad idea in code intended for public/general use; this is intended for a specific use-case where I need to trick source files into including something other than the standard library header for certain testing purposes.

It is important that users be able to write #include <foo.h> exactly, and not, say #include "foo.h" or #include "/path/to/foo.h" etc. Also, I do want other includes of files in /usr/include to work as usual (as much as possible; if they themselves include foo.h then I don’t care about them).

How do I arrange this in the C or C++ compiler command-line (e.g. with GCC, clang)?

Source: Windows Questions C++