Skip to content

Compiling a C Program

Visual Studio includes a C compiler that you can use to create everything from basic C programs to Windows API applications.
This post shows how to compile it on the command line.

By default, the Visual C++ compiler treats all files that end in .c as C source code, and all files that end in .cpp as C++ source code. To force the compiler to treat all files as C regardless of file name extension, use the /Tc compiler option.

1. Open a developer command prompt. In Windows 8, on the Start screen, choose the Developer Command Prompt for VS2012 tile. In earlier versions, choose the Start button, expand All Programs, Microsoft Visual Studio 2012, and Visual Studio Tools, and then choose Developer Command Prompt for VS2012.
Depending on the version of Windows on the computer and the system security configuration, you might have to open the shortcut menu for Developer Command Prompt for VS2012 and then choose Run as Administrator to successfully build and run the application that you create by following these steps.

Note: The Developer Command Prompt for VS2012 automatically sets the correct path of the C compiler and any required libraries. Use it instead of the regular Command Prompt window.

2. At the command prompt, specify the cl command together with the name of your source file.
For example: cl simple.c and press Enter to compile the program.
The cl.exe compiler generates an executable program that has the name of your source file, but has an .exe file name extension.
For example: Simple.exe.

You can see the executable program name in the lines of output information that the compiler displays.

source: Walkthrough: Compiling a C Program

You may also like...