如何使用Dev-C ++ IDE保存预处理器输出? [英] How do I save preprocessor output using the Dev-C++ IDE?

查看:97
本文介绍了如何使用Dev-C ++ IDE保存预处理器输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够查看预处理器输出,以确保我的预处理器指令正确运行.Dev-C ++在工具>编译器选项...>常规中有一个选项,可以在调用编译器时添加命令,并且我添加了命令-E C:\ Personal \ preprocessed.cpp.我收到一个编译器错误,指出该文件不存在,但在这种情况下,编译器不应该仅创建该文件吗?我创建了文件,现在出现此错误:无法将-o与-c,-S或-E一起指定多个文件.

I'd like to be able to view preprocessor output in order to make sure my preprocessor directives run correctly. Dev-C++ has an option in Tools > Compiler Options... > General to add commands when calling the compiler, and I've added the command -E C:\Personal\preprocessed.cpp. I got a compiler error saying the file didn't exist, but shouldn't the compiler just create the file in that case? I created the file, and now I'm getting this error: cannot specify -o with -c, -S or -E with multiple files.

为什么我使用Dev-C ++而不是Visual Studio?由于我仍在学习,因此我希望能够仅测试几行代码而不必创建

Why am I using Dev-C++ instead of Visual Studio? Since I'm still learning, I'd like to be able to test just a few lines of code without having to create an entire new project.

是的,我看过此问题,但未给出适当的答案.请不要将其标记为重复.

Yes, I've seen this question and no adequate answer was given. Please don't mark this as a duplicate.

提前感谢您的帮助!

推荐答案

我添加了命令-E C:\ Personal \ preprocessed.cpp.我收到一个编译器错误,提示该文件不存在,但在这种情况下编译器不应该只创建文件吗?

I've added the command -E C:\Personal\preprocessed.cpp. I got a compiler error saying the file didn't exist, but shouldn't the compiler just create the file in that case?

否,因为 -E 选项不带参数,文件名或其他参数.它只是指示编译器只做预处理.预处理的代码将写入标准输出.因此:

No, because the -E option takes no argument, filename or otherwise. It simply instructs the compiler to do nothing but preprocessing. The preprocessed code is written to the standard output. Thus:

因此:

g++ -E C:\Personal\preprocessed.cpp foo.cpp

通过一对输入文件 C:\ Personal \ preprocessed.cpp foo.cpp 告诉您要运行的 g ++ -E 编译器.代码>,您发现的内容是不允许的.

tells the compiler that you want run g++ -E with the pair of input files C:\Personal\preprocessed.cpp and foo.cpp, which as you've discovered is not allowed.

对于您要选择的IDE而言,您想做的简单事情是非常困难的.假设您要预处理的源文件是 C:\ Personal \ foo.cpp ,而 g ++ 在您的 PATH 中,只需在 C:\ Personal 中打开命令窗口并运行:

The simple thing that you want to do is absurdly difficult with your IDE of choice. Assuming the source file you want to preprocess is C:\Personal\foo.cpp and the g++ is in your PATH, just open a command window in C:\Personal and run:

g++ -E foo.cpp > foo.ii

我建议输出文件 foo.ii -尽管您可以随便叫它-因为 g ++ 将扩展名 .ii 识别为表示已经过预处理的C ++源代码.您可以运行:

I suggest the output file foo.ii - though you can call it whatever you like - because g++ recognizes the extension .ii as denoting C++ source code that has already been preprocessed. You can run:

g++ -Wall -o prog foo.ii

foo.ii 将作为程序 prog 进行编译和链接,而无需再次进行预处理.

and foo.ii will be compiled and linked as program prog without being preprocessed again.

这篇关于如何使用Dev-C ++ IDE保存预处理器输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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