54

I need to compile some files with a usage of modified versions of standard library headers. With Visual C++ compiler I will do this by usage of /X (Ignore Standard Include Paths) and /I (Additional Include Directories) parameters. How this should be done with gcc?

2 Answers 2

75
gcc -nostdinc -I/custom/include/path/goes/here 

-nostdinc ignores standard C include directories
-nostdinc++ ignores standard C++ include directories

Sign up to request clarification or add additional context in comments.

2 Comments

Not directly related, but is there way to give the least priority to standard includes..?
@Ramesh-X anything specified with -I should automatically take precedence over standard includes, IIRC
14

If you just add -I to your command line you will see (especially if you also add -v) that gcc will look in these folders first before looking in any other folders. So you don't need to add --nostdinc) in order to use an alternative STL library.

In this way STLPort is used:

g++ -I path-to-stlport-include main.cpp -L path-to-stlport-lib -lstlport

3 Comments

But in some cases it's better not to have standard include paths, so standard headers will not be included instead of one I'm using for replacement in case when that replacement is missing. From my POV it's much better to have compilation error in that case than confusing behavior of successfully compiled unit.
Some documentation for gcc: gcc.gnu.org/onlinedocs/gcc-7.5.0/gcc/…
This would certainly not work for #include_next in some system headers.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.