让 Notepad++ 使用 minGW 编译和运行 C++ 程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28131276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting Notepad++ to compile and run C++ programs using minGW
提问by Sankofa
I downloaded minGW to compile programs in C using the gcc command in the console of Notepad++. I downloaded all the packages so that it could compile other languages as well and I double checked that I have g++.exe just like I have gcc.exe to compile c programs. But I don't get how to get to compile and run c++ programs. I saw the other post, "Getting compiler to work in Notepad", and how he copied and pasted:
我下载了minGW,在Notepad++的控制台中使用gcc命令用C编译程序。我下载了所有软件包,以便它也可以编译其他语言,并且我仔细检查了我是否有 g++.exe,就像我有 gcc.exe 来编译 c 程序一样。但我不知道如何编译和运行 C++ 程序。我看到另一篇文章“让编译器在记事本中工作”,以及他是如何复制和粘贴的:
NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\MinGW\bin\g++.exe -g "$(FILE_NAME)"
into the nppExec console. When I do that I get:
进入 nppExec 控制台。当我这样做时,我得到:
NPP_SAVE: C:\Tutorial\helloWorld.cpp
CD: C:\Tutorial
Current directory: C:\Tutorial
C:\MinGW\bin\g++.exe -g "helloWorld.cpp"
Process started >>>
<<< Process finished. (Exit code 0)
================ READY ================
which seems like it works but what do I do next?
这似乎有效,但接下来我该怎么做?
here is the program in notepad++
这是记事本++中的程序
#include <iostream>
using namespace std;
int main() {
cout << "Hello World";
}
回答by Gábor Angyal
To be honest I have not tried the nppExec plugin before. (I usually use IDE.) But here is an educated guess:
老实说,我之前没有尝试过 nppExec 插件。(我通常使用 IDE。)但这是一个有根据的猜测:
What you typed in made the code compile, but did not execute the resulting executable. You need to specify the output file, and the run it. It is going to be something like this:
您输入的内容使代码编译,但没有执行生成的可执行文件。您需要指定输出文件,然后运行它。这将是这样的:
NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\MinGW\bin\g++.exe -g "$(FILE_NAME)" -o prog.exe
prog.exe
回答by π?ντα ?ε?
"which seems like it works but what do I do next?"
“这似乎有效,但接下来我该怎么做?”
Well, I think this way (mis-)using Notepad++ as an IDE, will at least become clumsy, if you want to manage more than a single source (.cpp
) file.
好吧,我认为这种(错误地)使用 Notepad++ 作为 IDE 的方式至少会变得笨拙,如果您想管理多个源 ( .cpp
) 文件。
As pointed out in Gábor Angyal's answer, the 1st step to go, is to compile an executable using the -o
option, and run the created program.
正如 Gábor Angyal 的回答中所指出的,第一步是使用该-o
选项编译可执行文件,并运行创建的程序。
Anyway you should note (if you insist on using Notepad++ instead of a realIDE), that MinGW also supports GNU make (here's a tutorial).
I would recommend to create a Makefile
and compile, link and run your code via this one.
无论如何,您应该注意(如果您坚持使用 Notepad++ 而不是真正的IDE),MinGW 也支持 GNU make(这是一个教程)。
我建议创建一个Makefile
并通过这个编译、链接和运行您的代码。
If it comes to debug your programs, I will definitely recommend an at least minimal IDE like CodeBlocksor Geany.
如果要调试您的程序,我肯定会推荐至少最小的 IDE,例如CodeBlocks或Geany。
Here's a more extended list of suggested Editors/IDE's: Best C++ IDE or Editor for Windows
这是建议的编辑器/IDE 的更多扩展列表:适用于 Windows 的最佳 C++ IDE 或编辑器
回答by Sujeet Garade
Working script :
工作脚本:
NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\g++.exe -g "$(FILE_NAME)"