How to compile CPP to EXE

Author: Joan Hall
Date Of Creation: 3 July 2021
Update Date: 1 July 2024
Anonim
Visual C++: Creating an Executable (.exe) File (2010)
Video: Visual C++: Creating an Executable (.exe) File (2010)

Content

This is a step-by-step guide to compiling C ++ source code to EXE files (on Windows). The described methods also work when compiling .c ++, .cc and .cxx formats (possibly .c as well). This tutorial assumes that the C ++ source code is a console application and does not require any external libraries.

Steps

  1. 1 Download the C ++ compiler. One of the best compilers for Windows computers is the free Microsoft Visual C ++ 2012 Express.
  2. 2 Start a new project in Visual C ++. It's pretty straightforward. Click "New Project" in the upper left corner and then follow the instructions on the screen. Enter the name of the project and in the window that opens, click "Finish".
  3. 3 Copy and paste all .cpp files into the "Source Files" directory, and then copy and paste all .h files (if any) into the "Header Files" directory. Rename the main CPP file (the one containing "int main ()") to your chosen project name.
  4. 4 Build and compile. Press the F7 key to create the program.
  5. 5 Find the EXE file. Change to the Projects directory where Visual C ++ puts all programs (on Windows 7, this directory is located in the My Documents folder). In the "Debug" directory, find the EXE file with the name you gave it earlier.
  6. 6 Check the file. Double click on the EXE file to run it; if everything went well, then the program works fine. If something went wrong, try the steps described again.
  7. 7 If you want to run the program on another computer, the VC ++ Runtime libraries must be installed on it (C ++ programs created with Visual Studio require these libraries). You don't need them on your computer as they are installed during the Visual Studio installation. Library download link: http://www.microsoft.com/en-us/download/details.aspx?id=30679

Tips

  • There is the possibility of errors due to the author's use of deprecated methods, or because the author forgot to include dependencies.
  • Install the latest version of Visual C ++ Express to avoid compile-time errors.
  • In most cases, the best solution is to ask the author of the program to compile it for you. Compile the program yourself only if absolutely necessary.

Warnings

  • Since C ++ and C are low-level programming languages, they can harm your computer. To avoid this, check the .cpp files for the "# include" windows.h "line.If such a line is present, do not compile the program, but ask its author why the program needs access to the Windows API. If the author is at a loss to answer, ask an expert on a specialized forum.
  • Don't work with Dev-C ++. It is an outdated compiler with 340 errors and has not been updated in 5 years.

What do you need

  • Compiler (Visual C ++ recommended).
  • CPP file or C / C ++ source code.
  • Windows computer (EXE format is only supported by Windows).