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

问题描述

我希望能够查看预处理器输出,以确保我的预处理器指令正确运行.Dev-C++ 在 Tools > Compiler Options... > General 中有一个选项可以在调用编译器时添加命令,我已经添加了命令 -E C:Personalpreprocessed.cpp.我得到一个编译器错误,说该文件不存在,但在这种情况下编译器不应该只创建文件吗?我创建了文件,现在我收到了这个错误:不能用 -c 指定 -o,不能用 -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:Personalpreprocessed.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 选项不接受任何参数、文件名或其他.它只是指示编译器除了预处理什么都不做.预处理后的代码被写入标准输出.因此:

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

因此:

g++ -E C:Personalpreprocessed.cpp foo.cpp

告诉编译器你想运行 g++ -E 与输入文件 C:Personalpreprocessed.cppfoo.cpp,正如您所发现的那样,这是不允许的.

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

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

The simple thing that you want to do is absurdly difficult with your IDE of choice. Assumingthe source file you want to preprocess is C:Personalfoo.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 保存预处理器输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 08:15