简体   繁体   English

gcc -MDD与-isystem <include_path> 不会为“系统”路径添加依赖项

[英]gcc -MDD with -isystem<include_path> wont add dependencies for “system” paths

So I have the following setup (simplified version): 所以我有以下设置(简化版):

application/app1.hpp
application/app1.cpp
application/utils/utils1.hpp
application/utils/utils1.cpp

So when I compile app1.cpp I do so like this (this is a cut-down version of the compile): 因此,当我编译app1.cpp时,我是这样的(这是编译的简化版本):

g++ -Wall -Wextra -Werror -I application -isystem application/utils -MMD -MP -MF dep.d -c application/app1.cpp -o obj.o

Where I use -MDD to auto generate dependency information. 我在哪里使用-MDD自动生成依赖项信息。 I use -isystem to inhibit warnings from files in utils folder. 我使用-isystem禁止来自utils文件夹中文件的警告。

Note: that utils is a sub-module (ie a seperate project that compiles on its own). 注意: utils是一个子模块(即,一个单独的项目,可以自己编译)。 Therefore I don't want compile warnings/errors from that project. 因此,我不想从该项目中编译警告/错误。 Therefore I am using -isystem application/utils to include folders. 因此,我正在使用-isystem application/utils来包含文件夹。 When you use isystem you don't get gcc warnings - which is great :) 当您使用isystem时,您不会收到gcc警告-很棒:)

However I just discovered that this is also the reason I am not getting complete depenecy outputs. 但是我刚刚发现,这也是我没有获得完整的penpenecy输出的原因。 Files included in the isystem directories are not added as dependecies in the gcc generated dep.d file. isystem目录中包含的文件不会作为依赖项添加到gcc生成的dep.d文件中。

So it seems I can either ignore the warnings from utils but not get depenency generation for it OR I can get the dependency output but not ignore the warnings. 因此,看来我可以忽略utils的警告,但不能获得依赖生成的信息,或者我可以获取依赖项输出,但不忽略警告。

I really want both: 我真的想要两个:

  • No warnings from utils utils没有警告
  • Dependencies from utils folder (via gcc's -MMD) utils文件夹中的依赖项(通过gcc的-MMD)

Is that possible to get both behaviours somehow? 是否有可能以某种方式获得两种行为?

Some ideas of mine: 我的一些想法:

  • I was thinking of somehow running the dependency pre-processor part on its own first and then the compile... but I did not see a way to do that 我正在考虑以某种方式先独立运行依赖项预处理器部分,然后运行编译...但是我没有找到一种方法来执行此操作
  • Force include folders in the MMD part. 强制在MMD部分中包含文件夹。 I found that I can include specific files with -include but not folders and I don't have a list of files :( 我发现我可以使用-include包含特定文件,但不能包含文件夹,并且我没有文件列表:(

I just found something that could work, but I am not sure how efficient it is. 我刚刚发现了可行的方法,但不确定其效率如何。 I found the -E gcc option which replaces -c (compile) with preprocess only). 我发现-E gcc选项仅将-c(编译)替换为预处理)。 So I could do: 所以我可以做:

  1. Generate the dependency info: 生成依赖项信息:

    g++ -I application -I application/utils -E application/app1.cpp -o /dev/null -MMD -MP -MF dep.d

  2. Compile the file with minimal warnings: 用最少的警告编译文件:

    g++ -Wall -Wextra -Werror -I application -isystem application/utils -c application/app1.cpp -o obj.o

This will mean that the preprocessor runs twice - not sure how much work that is... but it seems to run pretty quickly compared to the compile phase. 这将意味着预处理器运行两次-不确定该执行多少工作...但是与编译阶段相比,它似乎运行得很快。

If there is further ideas I am still very much open to them... I won't mark this answer for a while incase someone has a better idea... 如果还有其他想法,我仍然非常乐于接受...如果有人有更好的想法,我不会在一段时间内标记这个答案...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM