我正在尝试向大型开源项目添加新功能(例如 my_work.c)。为此,我需要访问几个字段,这些字段的声明和定义分布在现有代码库中。
我无法对所有字段“包含(头文件的路径)”,因为包含语句的数量将会很大。如何在不包含一堆内容的情况下访问所有字段。我想我可以通过在 Makefile 中添加函数 my_work.c 来获得此访问权限,但我不知道需要在哪里包含它?
最佳答案
How do I get access to all the fields without a bunch of includes.
你不知道。这就是包含的目的:访问外部代码。
但是,某些编译器,例如Clang 和 GCC,支持可用于插入隐式 #include
的标志:
来自man clang
:
-include <filename>
Adds an implicit #include into the predefines buffer which is read
before the source file is preprocessed.
来自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.
请注意,此方法仍将包含这些文件,因此您最好以正常方式执行此操作。
关于c++ - 访问大型 C/C++ 项目中的现有字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41403517/