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

Include header files using command line option?(使用命令行选项包含头文件?)
本文介绍了使用命令行选项包含头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

是否可以从命令行指定额外的头文件(使用 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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Prevent class inheritance in C++(防止 C++ 中的类继承)
Why should I declare a virtual destructor for an abstract class in C++?(为什么要在 C++ 中为抽象类声明虚拟析构函数?)
Why is Default constructor called in virtual inheritance?(为什么在虚拟继承中调用默认构造函数?)
C++ cast to derived class(C++ 转换为派生类)
C++ virtual function return type(C++虚函数返回类型)
Is there any real risk to deriving from the C++ STL containers?(从 C++ STL 容器派生是否有任何真正的风险?)