Tuesday, February 13, 2018

Notepad++ - Add C++ compiler





 1) One way to add  C++ compiler  is to use Pocket C++.
Pocket C++ can be downloaded from:
https://github.com/dacap/pocketcpp
After installation, You can use F9 key to compile C++ files, and Ctrl+F9 to execute the compiled program.
Recently I found there is popup windows to block
me compile C++ code.
2) second way is to install g++ compiler separately and
integrate in Notepad++.

a) Install g++ using Cygwin (http://www.edparrish.net/common/cygwin.php)
or using MinGW (https://nuwen.net/mingw.html)

b) Open the Plugin Manager in Notepad++.

Plugins > Plugin Manger > Show Plugin Manager

c) Find the NppExec plugin in the list and install it.

    Check the box
    Press the Install button

d) Open the NppExec Execute dialog.

NppExec > Execute...

e) Copy and paste the following script into the Commands box.
(assume g++ installed in C:\cygwin\bin\g++.exe. If using MinGW, replacing with MinGW g++ directory)

SET G++ = C:\cygwin\bin\g++.exe
NPP_SAVE // save current file
cd $(CURRENT_DIRECTORY) // go to directory of the current file
"$(G++)" -Wall -Wextra -Wpedantic -std=c++11 -o "$(NAME_PART)" "$(FILE_NAME)"


f) Save the script with a name like: C++ compile.

    Press Save button
    Enter the script name
    Press the Save button
   
g)To only compile, press the keys Ctrl-6 together or use the following set of menu commands:

 To both compile and run a program, press the keys Ctrl-7 together or use the following set of menu commands:

    Follow the menu to the NppExec Execute dialog

    Plugins > NppExec > Execute

    Select C++ compile and run script from the dropdown list.
    Press the OK button.
   
References:
https://github.com/dacap/pocketcpp
https://nuwen.net/mingw.html
http://www.edparrish.net/common/cygwin.php
http://www.edparrish.net/common/npp4c.html
https://stackoverflow.com/questions/27980134/how-to-compile-execute-c-code-from-within-notepad
http://preshing.com/20141108/how-to-install-the-latest-gcc-on-windows/