title: How to compile/execute C++ code from within Notepad++
body: <p>I was reading <a href="http://daleswanson.blogspot.com/2012/07/how-to-compile-c-code-in-notepad-with.html" rel="nofollow noreferrer">http://daleswanson.blogspot.com/2012/07/how-to-compile-c-code-in-notepad-with.html</a> and decided to try that, so that I can continue to write code in Notepad++ and have a shorter compile/run cycle.</p>
  
  <p>When I tried to enter compilation/run code into NppExec, it's not working.  The code I have now is:</p>
  
  <pre><code>npp_save
  cd "$(C:\Users\Bart\Desktop\new delete me)"
  g++ "$(test.cpp)" -o $(testme.exe) -march=native -O3
  NPP_RUN $(testme.exe)
  </code></pre>
  
  <p>That was based off the first link I gave:</p>
  
  <pre><code>npp_save
  cd "$(CURRENT_DIRECTORY)"
  g++ "$(FILE_NAME)" -o $(NAME_PART) -march=native -O3
  NPP_RUN $(NAME_PART)
  </code></pre>
  
  <p>Notepad++ gives me the following information in its Console:</p>
  
  <pre><code>NPP_SAVE: C:\Users\Bart\Desktop\new delete me\test.cpp
  CD: 
  Current directory: C:\Program Files (x86)\Notepad++
  g++ "" -o  -march=native -O3
  CreateProcess() failed with error code 2:
  The system cannot find the file specified.
  
  NPP_RUN:
  - empty command
  </code></pre>
  
  <p>From other pages it seemed as though I just needed to paste that code in, that the all caps words aren't meant to be replaced but are variables.  So I used this code:</p>
  
  <pre><code>npp_save
  cd "$(CURRENT_DIRECTORY)"
  g++ "$(FILE_NAME)" -o $(NAME_PART) -march=native -O3
  NPP_RUN $(NAME_PART)
  </code></pre>
  
  <p>Which gave the following in the Notepad++ Console:</p>
  
  <pre><code>NPP_SAVE: C:\Users\Bart\Desktop\new delete me\test.cpp
  CD: C:\Users\Bart\Desktop\new delete me
  Current directory: C:\Users\Bart\Desktop\new delete me
  g++ "test.cpp" -o test -march=native -O3
  CreateProcess() failed with error code 2:
  The system cannot find the file specified.
  
  NPP_RUN: test
  - the specified file was not found
  </code></pre>
  
  <p>Here's what I've done to get things set up:</p>
  
  <p>I downloaded mingw-get-setup.exe from <a href="http://sourceforge.net/projects/mingw/files/" rel="nofollow noreferrer">http://sourceforge.net/projects/mingw/files/</a> which installed the MinGW Installation Manager. I then used it to install the mingw32-gcc-++ package, as well as the mingw32-libz.dll and mingw32-libz.dev packages</p>
  
  <p>In Notepad++ I used the Plugin Manager to install the NppExec plugin.</p>
  
  <p>I can get my code to run by first manually compiling it in a command window.  Notepad++ complains that it's missing a library, so I'm using the following flags when I compile:
  g++ test.cpp -static-libgcc -static-libstdc++</p>
  
  <p>If I hit F5 in Notepad++ (or click Run in the Run menu), I can choose the a.exe file that's created from my command line compilation, and it will popup a command window and run that code, so that works fine.</p>
  
  <p>But it seems as though my change directory command isn't working for some reason in NppExec when I try to automate the compile/run.</p>
  
  <p>Here are some other stackoverflow posts I've found that address similar problems, but which don't seem applicable to me.  I don't have any points, so I can't reply to any of them:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/2506400/how-to-compile-and-run-c-files-from-within-notepad-using-nppexec-plugin">How to compile and run C files from within Notepad++ using NppExec plugin?</a></li>
  <li><a href="https://stackoverflow.com/questions/22730556/final-setup-of-gcc-in-notepad-using-nppexec">Final Setup of gcc in Notepad++ [using nppexec]</a></li>
  <li><a href="https://stackoverflow.com/questions/21523226/notepad-nppexec-createprocess-failed-with-error-code-2-windows-8-1">Notepad++, NppExec, CreateProcess() failed with error code 2, Windows 8.1</a></li>
  </ul>
  
  <p>Well, it looks like the first post I linked to has a partial solution -- it looked like (despite the mention of c files in the post name) that it was summarizing how to compile perl scripts.  It said to put the following in the NppExec window:</p>
  
  <pre><code>NPP_SAVE
  CD $(CURRENT_DIRECTORY)
  C:\MinGW32\bin\gcc.exe -g "$(FILE_NAME)"
  a.exe
  </code></pre>
  
  <p>It just had "a" on the final line, but that's the same as "a.exe" and it's more human readable this way.  That being said, this is not a full solution.  This just runs the file in Notepad++'s internal console, at the bottom of the screen and I'd like it to popup a window, as would happen if I used Notepad++'s F5 to run my compiled program from its directoy.</p>