【问题标题】:How to make compiler to search for only specific files in include directory and exclude the rest in that particular directory [duplicate]如何使编译器仅搜索包含目录中的特定文件并排除该特定目录中的其余文件[重复]
【发布时间】:2017-11-09 06:45:47
【问题描述】:

让我举一些我的问题的例子。假设我有两个目录,dir1 和 dir2。在每个目录中都有两个文件:dir1/fileA.h 和 dir1/fileB.h。 dir2 将有同名的文件 dir2/fileA.h & dir2/fileB.h,但它们的内容与 dir1 中的不同。如果我想使用 dir1/fileA.h & dir2/fileB.h,我的问题就出现了。如果我先包含 dir1 然后再包含 dir2

           INCLUDE_DIRS += \ dir1 \

                             dir2

那么编译器将只引用 dir1 中的 fileA.h 和 fileB.h,而忽略 dir2 中的文件,反之亦然,如果我将 dir2 先放在 dir1 之前。同样,是否有任何解决方案可以使编译器在 dir1 中查找 fileA.h 而在 dir2 中查找 fileB.h?

【问题讨论】:

  • #include "dir1/fileA.h"。或者,使用符号(或硬)链接或只是简单的旧副本来构建一个目录,其中只包含您想要的文件。你想做的事情超出了编译器可以处理的范围,你必须在编译器之外解决。

标签: c++ linux makefile include


【解决方案1】:

不,没有。但是假设你的dir1dir2 有一个共同的基本目录root,这样

   dir1 = the-root/path1
   dir2 = the-root/path2

然后,在您的Makefile 中使用-Ithe-root 作为编译选项

   target: source.c
         gcc -Ithe-root source.c ...

并包含在您的 C 文件中:

   #include "path1/fileA.h"
   #include "path2/fileA.h"

或任何你喜欢的。

【讨论】:

    猜你喜欢
    • 2021-09-11
    • 2015-02-07
    • 2016-08-12
    • 2013-03-08
    • 2023-01-04
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多