使用命令行选项包含头文件?

是否可以从命令行指定额外的头文件(使用 GCC 4/C + +) ?

除了 # include 之外,还有其他方法可以包含文件吗?

背景: 我试图在自己的 PC 上编译一个大型代码库。代码通常在集群中编译,并使用复杂的构建系统(SoftRelTools 有人吗?),它与操作系统交织在一起,因此实际上不可能在其他地方安装它(字面意思是数百个 makefile 和 shell 脚本,以及到网络驱动器的硬编码路径)。但是,实际的代码相当简单,编译也很好,但是缺少了很多包含的内容(主要是“ include <vector>”和“ include <math.h>”)。我猜测构建系统通常会处理这个问题,但是我必须仔细检查代码并手动添加包含内容,我宁愿避免这样做。

68763 次浏览

According to gcc documentation, the command line switch "-include file" would do the job.

I found the -include option. Does this what you want?

-include file

Process file as if "#include "file"" appeared as the first line of the primary source file. However, the first directory searched for file is the preprocessor's working directory instead of the directory containing the main source file. If not found there, it is searched for in the remainder of the "#include "..."" search chain as normal.

If multiple -include options are given, the files are included in the order they appear on the command line.

From the gcc manual:

-include file

Process file as if "#include "file"" appeared as the first line of the primary source file. However, the first directory searched for file is the preprocessor's working directory instead of the directory containing the main source file. If not found there, it is searched for in the remainder of the "#include "..."" search chain as normal.

If multiple -include options are given, the files are included in the order they appear on the command line.