Walkthrough: Compiling a C Program on Visual Studio 2010
Visual C++ 2010 includes a C compiler that you can use to create everything from basic C programs to Windows API applications.
This walkthrough shows how to create a basic C program by using a text editor, and then compile it on the command line.
You can use your own C programs instead of typing the sample programs shown in this walkthrough. You can also use any C code sample programs that are included in the Help topics.
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.
You must understand the fundamentals of the C++ language. If you are just getting started learning C++, we recommend the C++ Beginner's Guide by Herb Schildt, which is available on the MSDN Web site.
To create a C source file and compile it on the command line
Click Start, point to All Programs, Microsoft Visual Studio 2010, and Visual Studio Tools, and then click Visual Studio 2010 Command Prompt.
Depending on the version of Windows on the computer and the system security configuration, you might have to right-click Visual Studio 2008 Command Prompt and then click Run as Administrator to successfully run the application that you create by following these steps.
The Visual Studio 2010 Command Prompt automatically sets the correct path of the C compiler and any required libraries. Use it instead of the regular Command Prompt window. For more information, see Setting the Path and Environment Variables for Command-Line Builds.
At the command prompt, type notepad simple.c and press ENTER.
Click Yes when you are prompted to create a file.
In Notepad, type the following lines.
On the File menu, click Save to create a C source file.
Close Notepad.
At the command prompt, type cl simple.c and press ENTER.
The cl.exe compiler generates an executable program, Simple.exe.
You can see the executable program name in the lines of output information that the compiler displays.
To see a list of all files in the \simple\ directory, type dir simple.* and press ENTER.
The .obj file is an intermediate format file that you can safely ignore.
To run Simple.exe, type simple and press ENTER.
The program displays this text and exits:
This is a native C program.
To close the Command Prompt window, type exit and press ENTER.
No comments:
Post a Comment