What files are actually included at compilation

I have very large code, many of which are legacy code. I want to know which of these files is involved in the compilation. The code is written in GNU compilers and mostly in C / C ++, but some in other programs too. Any advice would be highly appreciated.

Thanks,

Moshe.

I compile on Linux using a set of scripts / make files. I want to somehow β€œwrap” this assembly with a tool that will give the result of all the source files used in the assembly, preferably with absolute path names.

What do you say?

+7
c ++ c gcc g ++
source share
4 answers

Two options come to mind.

  • Parsing the compilation log

    Run the assembly, save the log, and then search the log.

  • Find the files that open at compile time.

    For this, a system tracking tool, such as strace, or a library trace tool, such as ltrace , can be used, and then pay attention to open file calls.

    See also How can I detect file access on Linux?

+1
source share

If you want to show the included headers, then whether this is supported and how to do it depends on the compiler.

eg.

C:\test> (g++ --help --verbose 2>&1) | find "header" -print-sysroot-headers-suffix Display the sysroot suffix used to find headers --sysroot=<directory> Use <directory> as the root directory for headers -H Print the name of header files as they are used -MG Treat missing header files as generated files -MM Like -M but ignore system header files -MMD Like -MD but ignore system header files -MP Generate phony targets for all headers -Wsystem-headers Do not suppress warnings from system headers -print-objc-runtime-info Generate C header of platform-specific features -ftree-ch Enable loop header copying on trees C:\test> (cl /? 2>&1) | find "include" /FI<file> name forced include file /U<name> remove predefined macro /u remove all predefined macros /I<dir> add to include search path /nologo suppress copyright message /showIncludes show include file names C:\test> _ 

In the above you can see the corresponding options for g ++ and Visual C ++, respectively.

Cheers and hth.,

- alf

+10
source share

For a given compilation unit, for example. foo.cpp, add the -E -g3 flags to the g ++ call. This gives you pre-processed code. There you can see what things are included.

+2
source share
  • How do you create an application? That is, what do you type on the terminal to create it?
  • Depending on your answer to (1), find the appropriate program used for the build (i.e. make , scons , etc.)
  • Now find the input file for this build program, such as Makefile , SConstruct , etc.
  • Look at this assembly file and the other assembly files used by it to find out which source files are included in the assembly.
0
source share

All Articles