Is it possible to extract original filename (filepath) and compilation language from precompiled header? As I understand it's possible for Clang using llvm-bcanalyzer
(LLVM bit code analyzer). So, could anybody help me with GCC?
Asked
Active
Viewed 320 times
0

vromanik
- 196
- 1
- 4
-
A precompiled header most likely combines a lot (transcluded) .h files. What name exactly to do seek? – Kijewski Dec 08 '16 at 14:04
-
I tried to found the original header name which is the source for precompiled header. According to documentation you can create PHC using the follow command: gcc -x c-header **test.h** -o test.h.gch. In my case I would like to extract the path to **test.h** – vromanik Dec 08 '16 at 14:14
-
Yes. Clang allows me to receive that information [Clang PHC Internal metadata] (http://clang.llvm.org/docs/PCHInternals.html#ast-file-contents). – vromanik Dec 08 '16 at 14:21
1 Answers
2
For clang you can easily extract original PCH filename just parsing preprocessor output.
In out example header/header.h
is original header and pch/pch.h.gch
is precompiled header.
For example the follow command: clang -E -include pch/pch.h main.cpp
returns result where we can find original PCH filename:
…
# 1 "/Users/user/pch_example/header/header.h" 1
…
# 1 "main.cpp" 2
int main() {return 42;}
Unfortunately parsing preprocessor output doesn’t help us with GCC, even if you use it with -fpch-preprocess
option. So the only one way I found is compiling PCH with enabled dependency-tracking flag like -MD (or -MMD)
.
For example we can call the follow command: gcc-6 -MMD -x c++-header header/header.h -o pch/pch.h.pch
. In this case GCC additionally generates dependency-file pch/pch.h.d
, which contains path to the original PCH filename.

vromanik
- 196
- 1
- 4