I have a very large code, a lot of which is legacy code. I want to know which of all these files are taking part in the compilation. The code is written in GNU compilers and mostly in C/C++, but some in other programs too. Any advice will be highly appreciated.
Thanks,
Moshe.
I am compiling under linux with a mix of scripts/makefiles. I want to somehow 'wrap' this build with a tool which will give an output of all the source files used in the build, preferably with absolute path names.
What do you say?
If you want to show included headers then whether that's supported and how to do it depends on the compiler.
E.g.,
In the above you can see the relevant options for respectively g++ and Visual C++.
Cheers & hth.,
– Alf
make
,scons
, etc.)Makefile
,SConstruct
, etc.Here is a technique that finds all include files using
make
. It is non intrusive so you don't need to make any changes to files, or even to actually compile. Make will do all the work for you.will run make and emit lots and lots of lines describing the inner processing of the make process. The most important is the consideration of dependencies.
Parsing the output it is easy to find the dependencies, and all other files.
Here is a Linux command line that gets a sorted list of directories that contain include files:
In this case the directories are quoted and a comma is added at the end, so the ouput is ready to be included in Visual Studio Code (vscode) configuration file
c_cpp_properties.json
Simple variations can produce the grand list of include dependencies, like so:
This should also work with targets (e.g.
make All
)For a given compilation unit, e.g. foo.cpp, add the flags
-E -g3
to the call of g++. This gives you the preprocessed code. There you can look which things are included.Two options come to mind.
Parse the compilation log
Run a build, save the log, and then search in the log.
Find the files that are opened during the compilation time.
A way to do that might be to use a system tracing tool like strace or library tracing tool like ltrace and then look out for file open calls.
See also How can I detect file accesses in Linux?