c++ - 访问大型 C/C++ 项目中的现有字段

标签 c++ c makefile

我正在尝试向大型开源项目添加新功能(例如 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/

相关文章:

c++ - 如何在 Linux 上获得等效的 printf_l?

c++ - msvcprtd.lib(MSVCP100D.dll): fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

c - 在 C 文件中读取 : how do execute fgets on a same file multiple times?

c - 为什么包含对 fprintf 的调用会阻止我的程序出现段错误?

makefile - 在 GNU Make 中加入列表的元素

linux - 是否可以链接 16 位代码和 32 位代码?

c++ - 如何判断屏幕保护程序是否被暂时禁用?

c++ - std::function不起作用,但是普通的旧函数指针起作用-为什么?

c - 如何使用已调整的指针安全地释放内存

c++ - 从 Eclipse 中的现有 Makefile 推断包含路径和 make 目标