有没有办法用gcc查询直接模块的依赖关系? [英] Is there a way to query direct module dependencies with gcc?

查看:80
本文介绍了有没有办法用gcc查询直接模块的依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提供一个模块

// a-m.cc
export module A;

import B;
import C;

import "D.h";

...

是否有一种调用gcc的方法(类似于-M对标头所做的操作),该方法将列出对其他模块和导入的标头(即B,C和"D.h")的直接依赖关系?

Is there a way of invoking gcc (similar to what -M does for headers) that will list the direct dependencies on other modules and imported headers (i.e. B, C, and "D.h")?

推荐答案

我不知道gcc有什么办法,但是我建议编写一个辅助脚本来扩展文件并查找所有名为 import的东西.,那么您可能需要使用",""和"< "对导入进行排序,并将其作为标题输出.

I do not know any way for gcc to do it, but i would suggest writing a helper script that expands the file and looks for everything named import, then you might need to sort imports using " and < and output them as headers.

然后,您需要找到导出所选模块的文件,以使其与您的导入相匹配.那就是您需要浏览扩展的文件并查找以 export module 开头的语句.

Then you need to find which files exporting the selected module to match that with your import. That is you need to go through the expanded files and find statements beginning with export module.

您可以使用扩展文件

g++ -E {include flags, standard version etc} > tmpfile

-E 也可以与clang ++一起使用,但是对于msvc,您需要/E

-E works with clang++ aswell, but for msvc you need /E

如果有直接的方法可以用gcc做到这一点,我也想知道,但是随后出现了一个问题:gcc如何知道在哪里寻找模块?

If there is a direct way to do this with gcc I would also be interested to know, but the question then arises: How do gcc know where to look for the modules?

相反,如果您拥有一个跟踪每个模块位置的构建系统,则可以使用编译命令来指定它.(对于clang,您可以使用 -fmodule-file = 进行指定,我认为它与gcc相同,但尚未经过测试).至少这就是我在我的构建系统中所做的事情.

On the contrary if you have a build system that keeps track of where each module is located you can specify that as with compile commands. (With clang you specify this with -fmodule-file= i think it is the same with gcc, but have not tested). At least that is how I have done in my build system.

但总结一下我对您问题的回答.我认为您需要:

But to summarize my answer to your question. I think you need to:

  • 扩展您的源文件
  • 找到所有带有 import export import export模块的文件并进行处理.
  • Expand your source files
  • Find all files with import, export import and export module in them and process them.

这篇关于有没有办法用gcc查询直接模块的依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆