tags:

views:

156

answers:

2

Given the following:

  • large project with thousands of C++ source files
  • no common header file (no one header that's included in every source file)
  • said project is compiled with g++ and managed by make

Is there any way to include a definition (e.g. macro) into every compilation unit without modifying every source file to include a new header file?

+8  A: 

You can do this with the "-D" gcc command line option.

Example: gcc -ansi -Wall -Dblah='mymacrohere()' blah.cpp

See also: GCC Manual, Command Line options, Preprocessor options

SoapBox
+10  A: 

From man gcc:

-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.

Zitrax
Perfect! I was apparently only reading "man g++" which does not contain full documentation.
David Citron