Skip to content
Notepad.plus

How to Compile Your C Code in Notepad++ with Ease: A Step-by-Step Guide

Updated

Notepad++ with a C program open, ready to compile with GCC

Notepad++ is a fast, lightweight editor that's great for writing C code, but it isn't a compiler. To turn your .c files into programs you can run, you pair Notepad++ with a free C compiler called GCC and add a simple command that compiles and runs your code. It sounds complicated, but it only takes a few minutes to set up. In this step-by-step guide, we'll walk you through the whole process so you can start building your own programs in no time.

What You'll Need

You need three things: Notepad++ (download it here), the GCC compiler for Windows (MinGW-w64), and about 10 minutes.

Step 1: Install the GCC Compiler (MinGW-w64)

MinGW-w64 is a free version of the GCC compiler for Windows. The original MinGW project and its old website are no longer maintained, so use MinGW-w64 through one of these two options:

Option A: MSYS2 (recommended)

  1. Download and run the installer from the official MSYS2 website (msys2.org) and keep the default install folder, C:\msys64.
  2. Open the MSYS2 UCRT64 terminal from the Start menu.
  3. Run this command and press Y when asked to confirm:
Text
pacman -S mingw-w64-ucrt-x86_64-gcc

The compiler is installed in C:\msys64\ucrt64\bin.

Option B: WinLibs (no installer)

Download a GCC build for Windows from winlibs.com, extract the ZIP file, and move the mingw64 folder to C:\mingw64. The compiler is in C:\mingw64\bin.

Step 2: Add GCC to Your PATH

Adding the compiler's folder to the PATH environment variable lets Notepad++ and the Command Prompt find gcc from any folder.

  1. Press the Windows key and search for "environment variables".
  2. Click Edit the system environment variables.
  3. Click the Environment Variables… button.
  4. Under User variables, select Path and click Edit.
  5. Click New and add the bin folder from Step 1, for example C:\msys64\ucrt64\bin or C:\mingw64\bin.
  6. Click OK on all three windows.

To check that it worked, open a new Command Prompt and type:

Command Prompt
gcc --version

If you see a version number, you're ready. If you get "'gcc' is not recognized", double-check the folder path you added.

Step 3: Write and Save Your C Program

  1. Open Notepad++ and create a new file with Ctrl + N.
  2. Go to Language › C › C to turn on C syntax highlighting.
  3. Type this simple program:
C
#include <stdio.h>

int main(void) {
    printf("My first C program\n");
    return 0;
}

Then save the file with a .c extension, for example hello.c. Avoid spaces in the file name to keep things simple.

Step 4: Create a Compile-and-Run Command in Notepad++

Notepad++'s built-in Run menu can send your file to GCC with one keystroke.

  1. Go to Run › Run… (or press F5).
  2. In the The Program to Run box, paste this command:
Command Prompt
cmd /k gcc "$(FULL_CURRENT_PATH)" -o "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" && "$(CURRENT_DIRECTORY)\$(NAME_PART).exe"

Click Save…, name it "Compile and Run C", choose any unused keyboard shortcut, and click OK.

Here's what the command does:

  • $(FULL_CURRENT_PATH) is the full path of the file you have open.
  • $(CURRENT_DIRECTORY) and $(NAME_PART) build the output file name, so hello.c becomes hello.exe in the same folder.
  • && runs your program only if it compiled without errors.
  • cmd /k keeps the window open so you can read the output or error messages.

Step 5: Compile and Run Your Code

  1. Save your file first with Ctrl + S. The command always compiles the saved version.
  2. Choose Run › Compile and Run C or press the shortcut you picked.
  3. A Command Prompt window opens. If there are no errors, you'll see "My first C program". If there are errors, GCC lists them with line numbers so you can fix them and run the command again.

You'll also find a new file, hello.exe, next to your hello.c file. That's your compiled program.

Optional: See Output Inside Notepad++ with NppExec

If you'd rather see compiler output in a panel inside Notepad++, install the NppExec plugin from Plugins › Plugins Admin… (learn more about finding and installing plugins). Then open Plugins › NppExec › Execute NppExec Script… (F6), paste this script, and save it:

Text
NPP_SAVE
cd "$(CURRENT_DIRECTORY)"
gcc "$(FILE_NAME)" -o "$(NAME_PART).exe"
"$(NAME_PART).exe"

The script saves your file, compiles it, and runs it, with all output shown in the NppExec console at the bottom of the window. For programs that read keyboard input (for example with scanf), the Run menu method from Step 4 usually works better.

Troubleshooting Common Problems

  • "'gcc' is not recognized as an internal or external command": the compiler folder isn't in your PATH, or Notepad++ was already open when you changed PATH. Recheck Step 2, then close and reopen Notepad++.
  • "No such file or directory": save the file before compiling, and make sure the command keeps the quotation marks around paths.
  • "undefined reference to WinMain": your file has no main function, or it's misspelled.
  • Your antivirus blocks the new .exe: some antivirus tools flag brand-new programs. Add your projects folder as an exclusion if you trust your own code.

Conclusion

That's it! Once GCC is installed and the Run command is saved, compiling C code in Notepad++ takes a single keystroke. This setup is perfect for learning C, practicing exercises, and building small programs. If you're also learning C++, see our guide on how to compile and run C++ programs in Notepad++, and before adding plugins like NppExec, check out our guide to plugin safety.