PDF download Download Article
A foolproof tutorial to creating .exe applications from your C/C++ programs
PDF download Download Article

If you use the commercial version of Microsoft Visual Studio to code, it has a built-in C/C++ compiler that's easy to use. If you're using Visual Studio code or a different editor without a compiler, you can use a port of GCC and G++ called MinGW). This guide assumes that your source code is for a console application and does not require any outside libraries. Read on to learn how to convert C++ code (CPP files) into an executable EXE file.

Quick Steps

  1. Install MSYS2 for Windows.
  2. Open an MSYS2 terminal and run the command to install MinGW.
  3. Add the compiler's path to your user environment variables.
  4. Use "g++ yourprogram.cpp " at the prompt or run the compiler from VS Code.
Method 1
Method 1 of 2:

Using MinGW

PDF download Download Article
  1. If you're using Visual Studio Code or another development environment that doesn't come with a compiler, you can use the MinGW GCC and G++ compiler to turn CPP files into executables, just like in Linux . To get started, head to https://www.msys2.org/ and click the link next to Download the installer , then double-click the installer to run it. [1]
    • When installing, choose a short name for your install folder with no special characters, e.g., C:\msys64.
    • You should install MSYS2 on an NTFS volume on the local machine, not on a network drive. [2]
  2. The MSYS2 terminal should open automatically after installation. If it doesn't, open the MSYS2 folder in the Windows menu, then select MSYS2 UCRT64 .
    Advertisement
  3. To do this:
    • Type this command into the terminal and press Enter : pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain .
    • When you see the list of tools, press Enter to install all of them at once.
    • Press Y to proceed with installation. [3]
    • Once the installation is complete, MinGW's version of GCC/G++ will be installed and ready to use.
  4. Now you'll want to add the compiler's installation path to your Windows environment variables so you can run it from command prompt.
    • Right-click the Windows menu and select Settings .
    • In the search bar, type environment variables . You should see two search results.
    • Click Edit environment variables for your account .
  5. Here's how:
    • Select Path under "User variables" and click the Edit… button.
    • Click New .
    • Add the path to the ucrt64\\bin\ folder inside the MSYS2 folder you created. For example, if you installed MSYS2 in C:\MSYS2, type C:\MSYS2\ucrt64\bin .
    • Click OK
  6. If you're using Visual Studio Code, you can now easily compile and run your C++ program from within the editor. Here's how:
    • Reopen your CPP file in VS Code.
    • Click the Play button at the top-right and select Run C/C++ File .
    • From the list of compilers, select C/C++: g++.exe build and debug active file . You'll only have to do this the first time you use the compiler.
    • Once selected, your program will be compiled, and you'll see the output in the terminal.
  7. If you just want to compile the CPP file into EXE at the prompt, it's easy:
    • Right-click the Start menu and select File Explorer .
    • Open the folder that contains your CPP file(s).
    • Hold the ⇧ Shift key as you click an empty area in the folder, then select Open Command window here .
      • If you're using Windows 11, select Open in Terminal , click the down arrow at the top of the Terminal, and select Command Prompt .
    • Type g++ yourprogram.cpp (replace that name with the name of your actual CPP file) and press Enter to compile the CPP file into an EXE. As long as there are no errors in your C++ code, a new file ending in "EXE" will appear in the current folder. [4]
  8. Advertisement
Method 2
Method 2 of 2:

Using Microsoft Visual Studio

PDF download Download Article
  1. You'll find it in the Start menu. Use this method if you're using the full IDE commercial version of Visual Studio.
    • If you're using a free coding app like Visual Studio Code or want to compile from the command prompt, see the Using MinGW method.
  2. If you haven't already done so, click the File menu, select New , and then select Project . [5] A dialog window will appear.
  3. The steps are a little different depending on the version you're using: [6]
    • Visual Studio 2019: Select C++ from the "Language" menu, Windows from the "Platform" menu, and then Console as the "Project type." Select Console App , click Next , enter a project name, and then click Create .
    • Visual Studio 2017: Click Windows Desktop and then Windows Console Application . Type a name for the project and click OK . [7]
  4. If you don't already see a window with this name, click the View menu and select Solution Explorer to display it now.
  5. The folder is in the Solution Explorer. You can drag them there from another window. Rename the main CPP file (the one that contains "int main()") to the name of the project that you chose if it's not already the same. [8]
    • If you have any .H files, add them to the "Header Files" directory.
  6. It's at the top of the window. [9]
  7. This compiles your program into the EXE format. Your build results will appear in the "Output" window at the bottom of the workspace.
    • To test your program from Visual Studio, click the Debug menu and select Start without debugging.
    • To test it from the File Explorer, right-click the name of your app in the Solution Explorer window, select Open Folder in File Explorer , and then double-click the Debug folder—you'll find your app here.
  8. Advertisement

Community Q&A

Search
Add New Question
  • Question
    Is Turbo C+ good for compiling C++ programs?
    Community Answer
    It is a good compiler, but it's outdated and doesn't support modern C++. I would recommend Visual Studio instead.
  • Question
    Can I run trurboC3 file in visual studio without any problem?
    Community Answer
    Yes, you can. Just locate the file in the location of computer and open it with visual studio or you directly access it from visual studio just search the file and run it.
  • Question
    How do I rename the executable file from .exe to any other name?
    Community Answer
    Right Click your project in Solution Explorer. Click on the Properties. Select the application tab. Change the assembly name to whatever new name you want to have of your exe.
Ask a Question
      Advertisement

      Video

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!

      About This Article

      Article Summary X

      1. Open Visual Studio.
      2. Set up your project.
      3. Add your CPP code to the "Source Files" folder.
      4. Click the Build menu.
      5. Click Build Solution .

      Did this summary help you?
      Thanks to all authors for creating a page that has been read 559,070 times.

      Is this article up to date?

      Advertisement