Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Notepad++ to compile and run C++ programs using minGW

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:

NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\MinGW\bin\g++.exe -g "$(FILE_NAME)"

into the nppExec console. When I do that I get:

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";

}
like image 214
Sankofa Avatar asked Jan 24 '15 23:01

Sankofa


2 Answers

To be honest I have not tried the nppExec plugin before. (I usually use IDE.) But here is an educated guess:

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
like image 73
Gábor Angyal Avatar answered Oct 05 '22 12:10

Gábor Angyal


"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.

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.

Anyway you should note (if you insist on using Notepad++ instead of a real IDE), 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.

If it comes to debug your programs, I will definitely recommend an at least minimal IDE like CodeBlocks or Geany.

Here's a more extended list of suggested Editors/IDE's: Best C++ IDE or Editor for Windows

like image 32
πάντα ῥεῖ Avatar answered Oct 05 '22 14:10

πάντα ῥεῖ