Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

Dump include paths from g++

I'm trying to write a little build script, and want to determine if the includes are system includes or not. So I want g++ to tell me the include path's it's using.

cpp -v seems the obvious best shot, but it doesn't give me the C++ paths.

So I tried:

g++ -Xpreprocessor -v  

Which doesn't work quite right - g++ captures the -v for it's own verbose output.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

From Jonathan Wakely a better option (works on clang too):

g++ -E -x c++ - -v < /dev/null 
clang++ -E -x c++ - -v < /dev/null

I noticed there's a flag in cpp for specifying language. This works like a charm.

cpp -xc++ -v < /dev/null


#include "..." search starts here:
#include <...> search starts here:
 /usr/local/Cellar/gcc/4.7.0/gcc/lib/gcc/x86_64-apple-darwin11.4.0/4.7.0/../../../../include/c++/4.7.0
 /usr/local/Cellar/gcc/4.7.0/gcc/lib/gcc/x86_64-apple-darwin11.4.0/4.7.0/../../../../include/c++/4.7.0/x86_64-apple-darwin11.4.0
 /usr/local/Cellar/gcc/4.7.0/gcc/lib/gcc/x86_64-apple-darwin11.4.0/4.7.0/../../../../include/c++/4.7.0/backward
 /usr/local/Cellar/gcc/4.7.0/gcc/lib/gcc/x86_64-apple-darwin11.4.0/4.7.0/include
 /usr/local/include
 /usr/local/Cellar/gcc/4.7.0/gcc/include
 /usr/local/Cellar/gcc/4.7.0/gcc/lib/gcc/x86_64-apple-darwin11.4.0/4.7.0/include-fixed
 /usr/include
 /System/Library/Frameworks
 /Library/Frameworks
End of search list.

Just noticed that it is important for the -x c++ to be -xc++ on gcc 4.2


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...