Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract all included files in cpp

Tags:

c++

include

I have .cpp file (text).I want to get the list of all files names which are included (#include) to this file. What is the best way to do it?(Need to implement it in C++)

like image 974
Yakov Avatar asked Oct 22 '22 19:10

Yakov


2 Answers

gcc -M source.cpp

Replace -M with -MM if you don't care about the system includes.

like image 186
ipc Avatar answered Oct 30 '22 23:10

ipc


Assuming you have a "find" or "grep", something along these lines:

g++ -E source.cpp | grep '\# 1 '

like image 35
Mats Petersson Avatar answered Oct 31 '22 00:10

Mats Petersson