Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast way to identify necessary includes for C++ [duplicate]

Tags:

c++

include

On Linux, what is a fast way to identify what are the necessary #include statements that I need for a C++ project?

I mean, let's say someone gives you a snippet from the web, but fails to provide the necessary #include statements. Is there potentially a way where you can run a Linux command or compiler command option and identify which functions or classes are missing, and, as a bonus, identify on the hard drive where I might have these things in a header file.

like image 622
Volomike Avatar asked Nov 02 '22 14:11

Volomike


1 Answers

Basically you need some analyzer to parse your sources and headers and build a complete dependency graph which it spits out in the end for you to read and process further.

I'd follow john's advice on g++ and Clang for this purpose but I highly doubt they got what it takes.

What you actually can do, at least with g++, is print out a graph for already existing includes. Use the -H option to print a tree or -M to get a list.

I also refer you to this related topic: Tool to track #include dependencies

Not exactly what you want, but the tools mentioned there might be helpful.

like image 94
thokra Avatar answered Nov 13 '22 19:11

thokra