Include header files using command line option?

C++GccInclude

C++ Problem Overview


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

Or is there any other way files can be included except with #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.

C++ Solutions


Solution 1 - C++

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.

Solution 2 - C++

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.

Solution 3 - C++

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjdmView Question on Stackoverflow
Solution 1 - C++foraidtView Answer on Stackoverflow
Solution 2 - C++YuppieNetworkingView Answer on Stackoverflow
Solution 3 - C++tiburView Answer on Stackoverflow