编译时实际包含哪些文件

Mos*_*she 7 c c++ gcc g++

我有一个非常大的代码,其中很多是遗留代码.我想知道所有这些文件中哪一个参与编译.代码是用GNU编译器编写的,主要用C/C++编写,但也有一些在其他程序中编写.任何建议将受到高度赞赏.

谢谢,

卡察夫.

我在linux下编译混合脚本/ makefile.我想以某种方式用一个工具"包装"这个构建,该工具将给出构建中使用的所有源文件的输出,最好是具有绝对路径名.

你说什么?

Che*_*Alf 10

如果要显示包含的标题,那么是否支持它以及如何执行它取决于编译器.

例如,

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> _
Run Code Online (Sandbox Code Playgroud)

在上面,您可以分别看到g ++和Visual C++的相关选项.

干杯&hth.,

- 阿尔夫


Aru*_*run 1

我想到了两个选择。

  1. 解析编译日志

    运行构建,保存日志,然后在日志中搜索。

  2. 查找编译期间打开的文件。

    一种方法可能是使用strace等系统跟踪工具或ltrace等库跟踪工具,然后查找文件打开调用。

    另请参阅如何检测 Linux 中的文件访问?