有没有办法自动在所有C或CPP文件中包含头文件? [英] Is there any way to include a header file in all C or CPP file automatically?
问题描述
可能存在重复:
如何通过makefile包含头文件
我使用gcc编译我的代码。我也有几个make文件。我可以告诉编译器将一个特定的头文件包含在所有CPP文件中。
I am using gcc for compiling my code. I have a few make files also. Can I tell the compiler to include a particular header file to be automatically included in the all CPP files.
我该怎么做?
推荐答案
添加合适的预处理器选项为 gcc
添加到您的 Makefile
-s并且有一个 common_feature_header.h
定义这些的头文件。
Add the appropriate preprocessor option for gcc
to your Makefile
-s and have a common_feature_header.h
header file defining these.
# in Makefile
CPPFLAGS+= -include common_feature_header.h
如果您只想定义一些预处理器标志,则不需要 common_feature_header.h
文件,但只需将 Makefile
添加到以下定义中即可:
If you just want to define some preprocessor flags, you don't need a common_feature_header.h
file, but simply add into your Makefile
the following definition
CPPFLAGS+= -DSOME_FEATURE_FLAG=1 -DSOME_OTHERFEATURE_FLAG=0 \
-DYET_ANOTHER_THING=2
另见这个答案。
您可能希望使用重拍(特别是使用 -x
选项)来调试你的 Makefile
。
P.S. You may want to use remake (notably with its -x
option) to debug your Makefile
.
这篇关于有没有办法自动在所有C或CPP文件中包含头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!