Locate the path of STL headers used by g++
Asked Answered
D

1

8

I need to look something up in the debug version of std::vector<T>, and I can't remember where the headers actually are. This is under MSYS on Windows, where this is tricky, because you have /include, /mingw/include, /mingw/mingw32/include, /usr/include, and I still can't find them...

I know one way, that is to write a file like this:

#include <vector>

int main() {
    return 0;
}

Then

$ g++ -E temp.cpp | grep vector

And we find that it's here: /mingw/lib/gcc/mingw32/4.8.1/include/c++/vector

But is there a faster way? Can we ask g++ without using this trick?

Dereism answered 14/1, 2014 at 10:5 Comment(0)
A
13

You can display the full search paths with

g++ -print-search-dirs

or you can find a specific header without writing a source file with something along the lines of

echo '#include <vector>' | g++ -x c++ -E - | grep '/vector"'
Ash answered 14/1, 2014 at 10:18 Comment(1)
That's great! For Windows users like me, the slash in the grep pattern should be dropped.Dereism

© 2022 - 2024 — McMap. All rights reserved.