How to Compile CPP File to EXE

This tutorial will give you a step-by-step guide for converting C++ source files into .exe files, runnable on most (to avoid the word "all") Windows computers. Other extensions this will work with are .cpp, .cc, and .cxx (and .c to an extent, however don't rely on it working). This guide assumes that the C++ source code is for a console application and does not require any outside libraries.


  1. Image titled Compile CPP File to EXE Step 1
    First you need to get a C++ compiler. One of the best for Windows machines is the free Microsoft Visual C++ 2012 Express.
  2. Image titled Compile CPP File to EXE Step 2
    Start a new project in Visual C++. This is pretty simple. Click the "New Project" button in the top left, then follow the steps to make an "Empty Project". Then name it, and on the next pop-up hit "Finish".
  3. Image titled Compile CPP File to EXE Step 3
    Copy and paste all of the .cpp files into the "Source Files" directory, and copy-paste all the .h files (if there are any) into the "Header Files" directory. Rename the main .cpp file (the one that contains "int main()" in it) to the name of the project that you chose. The external dependencies file will fill itself
  4. Image titled Compile CPP File to EXE Step 4
    Build and compile. Press the [F7] key after you have finished all of the above and the program will be created.
  5. Image titled Compile CPP File to EXE Step 5
    Find the exe file. Navigate to the "Projects" file that Visual C++ installs all of the programs to (in Windows 7, it will be in your Documents). It will be in the file with the name you gave it earlier, under the "Debug" directory.
  6. Image titled Compile CPP File to EXE Step 6
    Test it. Double-click on the .exe file to run it, and if everything went well, the program should work fine. If it doesn't, try going through the steps again.
  7. 7
    If you want the program to run on another computer as well, that computer must have VC++ Runtime libraries installed. C++ programs built using Visual Studio require them. You won't need it on your machine because it gets installed with Visual Studio. But you can't expect your clients to have it. Download Link:


  • Sometimes, errors may be generated because the original author may have used deprecated methods or forgot to include dependencies of the source code.
  • Make sure that you have Visual C++ Express up-to-date, so that there will be no errors at compiling time.
  • In most cases, it is more efficient just to get the creator to compile it for you. Only compile it yourself if you absolutely must.


  • Because C++ and C are very low-level programming languages, they have the potential to harm your computer. A quick check that you can do is to check if the .cpp files have the line "#include "WINDOWS.h" at the top. If they do, then do NOT compile the program yet and ask the user why they need to have access to the Windows API. If they cannot supply a sufficient answer, ask an expert at a forum for help.
  • STAY AWAY from Dev-C++. It has an outdated compiler, over 340 known bugs, and has not been updated for 5 years, staying in perpetual beta. If at all possible, use ANY OTHER COMPILER AND IDE BUT THAT ONE.

Things You'll Need

  • A compiler (Visual C++ is recommend)
  • A cpp file or C/C++ source-code
  • A Windows computer (.exe is only supported by Windows)

Article Info

Categories: File Manipulation