Include one header file in each source file

后端 未结 4 542
心在旅途
心在旅途 2021-01-19 14:50

Say you have 100s of source files (.c or .cpp) files, and you want to include some definitions, function/variable declarations in each of them. Normally in C/C++, you use he

4条回答
  •  孤街浪徒
    2021-01-19 15:49

    You can't do that, although you could write a script for you to do it. A script that takes each files, and writes #include "header.h" at top. Edit: -include in gcc does this.

    However, what you need is achievable in a different way through the compiler options. In gcc, with -D.

    Let's say, you want the define DEBUG_LEVEL to 2 in all your source files. You can simply do this by invoking gcc like this:

    gcc -DDEBUG_LEVEL=2
    

    Note that in this case, you would need to rebuild all your project (which would have been done anyway if you had changed this definition in 1 header file to which ALL the source files depend on)

提交回复
热议问题