使用命令行选项包含头文件? [英] Include header files using command line option?

查看:36
本文介绍了使用命令行选项包含头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to specify extra header files to include from the command line (using GCC 4 / C++)?

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

Or is there any other way files can be included except with #include?

背景:我正在尝试在自己的 PC 上编译大型代码库.代码通常在集群中编译,使用复杂的构建系统(有人使用 SoftRelTools 吗?),它与操作系统交织在一起,因此几乎不可能将其安装在其他地方(字面意思是数百个 makefile 和 shell 脚本,并且很难到网络驱动器的编码路径).然而,实际的代码相当简单,编译得很好,但它缺少很多包含(主要是include "和include ";").我猜构建系统通常会处理这个问题,但我必须仔细检查代码并手动添加包含,我宁愿避免这种情况.

Background: I'm trying to compile a large code base on my own PC. The code is usually compiled in a cluster, with a complicated build system (SoftRelTools anybody?), which is intertwined with the operating system, such that it is virtually impossible to install it somewhere else (literally hundreds of makefiles and shell scripts, and hard coded paths to network drives). However, the actual code is fairly straightforward, and compiles fine, BUT it is missing a lot of includes (mostly a la "include <vector>" and "include <math.h>"). I'm guessing the build system takes care of this usually, but I have to go through the code and add the includes manually, which I'd rather avoid.

推荐答案

I found-include 选项.这是你想要的吗?

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

-包含文件

处理文件就好像#includefile""出现在第一行主要源文件.但是,那搜索文件的第一个目录是预处理器的工作目录而不是包含的目录主要源文件.如果没有找到在那里,它在"#include "..."" 的其余部分搜索链正常.

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.

如果给出多个 -include 选项,则文件包含在它们出现在命令行中的顺序.

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

这篇关于使用命令行选项包含头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆