Blog Archive

Wednesday, April 20, 2011

How to: Compile a Native C++ Program from the Command Line

To create a Visual C++ source file and compile it on the command line

Open the Visual Studio 2005 Command Prompt window.

Click the Start button, then point to All Programs, Microsoft Visual Studio 2005, Visual Studio Tools, and click Visual Studio 2005 Command Prompt.

Note
The Visual Studio 2005 Command Prompt automatically sets up the correct path to the Visual C++ compiler and any needed libraries, so it is used 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.cpp and press Enter.

Click Yes when prompted to create a new file.

In Notepad, type the following lines:

#include

int main()
{
std::cout << "This is a native C++ program." << std::endl;
return 0;
}
On the File menu, click Save. You have created a Visual C++ source file.

On the File menu, click Exit to close Notepad.

At the command line prompt, type cl /EHsc simple.cpp

No comments:

Post a Comment