具有参数“g -save-temps”的gcc将中间文件放入当前目录 [英] gcc with parameters "-S -save-temps" puts intermediate files in current directory

查看:242
本文介绍了具有参数“g -save-temps”的gcc将中间文件放入当前目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参数 -S -save-temps 可以正常工作,只要我不在具有相同名称的文件上使用它们即可。



考虑以下情况:我有一个名为 subDir 的主目录和子目录的项目,并且这两个目录都是文件放置名称 file.c 。如果我现在调用 gcc -S -save-temps file.cpp subDir / file.c ,只有一个中间文件名为 file.i 将被生成。

这是预期的行为,因为 gcc 的man文件告诉我使用 -save-temps



我的问题是,我正在进行事先不知道的项目。很可能,有人在他的Makefiles中构建了上述示例。在这种情况下,我会被卡住,因为我需要两个中间文件。



我正在构建的系统的几个词(为了更好的理解):我的工具使用 make --just-print 来收集调用,一个项目的make文件调用。我扫描这些调用以进行编译调用,并添加 -save-temps -S 选项。其目的是获取每个预处理文件,这是在编译项目过程中使用的。



您有任何想法,我如何能够获得每个预处理文件,即使上面提到的例子应该出现?

解决方案

file.cpp / file.c在不同的目录中没有问题。 GCC将根据文件的扩展名创建一个 *。ii 和一个 *。i



如果他们都有c || cpp,你可以使用 -E 并且只接收一个 *。i 您可以在其中搜索pragma #1< FILE_PATH>并通过脚本提取它。


The parameters -S -save-temps work fine, as long as i don't use them on files with the same name.

Think of the following situation: I have a project with a main directory and a subdirectory with the name subDir and in both of the directories are files placed with the name file.c. If I now call gcc -S -save-temps file.cpp subDir/file.c only one intermediate file with the name file.i will be generated.

That is the expected behaviour, as the man file of gcc tells me, that the intermediate files will always be placed in the current path, when using -save-temps.

My problem is, that I'm working on projects I don't know in advance. It could very well be, that someone constructed the above mentioned example in his Makefiles. In that case I would be stuck, because I need both intermediate files.

A few words to the system I'm constructing (for better understanding): My tool uses make --just-print to collect the calls, a make file of a project invokes. I scan these calls for compiler calls and add the -save-temps and -S options. The purpose is to get every preprocessed file, that is used in the process of compiling the project.

Do you have any ideas, how I'm able to get every preprocessed file, even if the above mentioned example should appear?

解决方案

There's no problem with file.cpp / file.c in different directories. GCC will create a *.ii and a *.i depending on the files' extension.

If they both have c||cpp you can use -E and receive only one *.i where you can search for the pragma # 1 "<FILE_PATH>" and extract it via a script.

这篇关于具有参数“g -save-temps”的gcc将中间文件放入当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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