Using Visual C ++ Toolkit 2003 from The Command Prompt

xiaoxiao2021-03-06  61

Brian JohnsonMsdn Visual C Content Strategist

November 2004

Applies TO: Visual Studio .NET 2003 Microsoft Visual C .NET 2003 Microsoft Visual C Toolkit 2003

Summary:.. In this article, Brian Johnson describes how to use the Microsoft Visual C compiler that ships with the Visual C Toolkit 2003 from the command line This article is for beginners who've never used a command line compiler before (4 printed pages )

The Visual C Toolkit 2003 package is designed to enable developers to build and test applications with the full optimizing compiler that ships with Visual Studio .NET 2003. This package is not a substitute for the full version of the product; rather, it's a subset that lets you evaluate and explore the optimizing compiler. In addition, it will let you build small applications suitable for academic study. I've written this article to help readers who are very new to C learn how to use the Visual C Toolkit 2003 compiler From The Command Line to Build Simple Applications.

The Visual C Toolkit 2003 does not contain any sort of IDE, and so you'll need to build applications using the compiler the old fashioned way, with a text editor and command prompt. In this article, I'll outline the steps that You need to take to build and rain applications with the Visual C Toolkit 2003 USING Only Notepad and a commnd prompt.

To get started, you'll need to install the Visual C Toolkit 2003 package. We have a toolkit home page at http://msdn.microsoft.com/visualc/vctoolkit2003 that provides a link to the download center page. Visit that page and download and install the compiler. To help you get started, you will also find articles and a frequently asked questions list.After you install the toolkit, you'll find a new Visual C Toolkit 2003 folder on your Start menu. This menu contains a link to the Visual C Toolkit 2003 Readme file and it includes a shortcut to the Visual C Toolkit 2003 Command prompt. We'll do all of our work from this shortcut to the command prompt, so go ahead and click on it to open it NOW.

The Visual C Toolkit 2003 Command Prompt Sets a Number of Paths and Options That Are Required for building Applications with the Compiler. The key settings That The Compiler Requires Are That:

SET PATH = C: / Program Files / Microsoft Visual C Toolkit 2003 / bin;% PATH%

SET include = C: / Program Files / Microsoft Visual C Toolkit 2003 / include;% incrude%

Set lib = C: / Program Files / Microsoft Visual C Toolkit 2003 / LIB;% LIB%

These settings place the path of the Visual C Toolkit 2003 at the beginning of your PATH variable. Likewise, the INCLUDE variable sets the path to the header files that ship with the toolkit, and the LIB variable sets the path to the library files that ship with the toolkit. The header files declare the functions available in the library files and make accessible from your application. I'm not going to them cover too much of that in this article, but you will find some recommended books for learning C at the end of this article.The Microsoft C command line compiler is named CL.EXE. To compile a C application using this tool, you'll normally write your application using a text editor such as Notepad, save the file with an extension of .cpp And the invoke the compiler, passing the name of the file this you want to compile as a parameter. Let's go ahead and do this now.

The first application that's traditionally built when learning a language is Hello World This is a simple application that prints the words "Hello World!" To your command prompt The standard C Hello World application looks like this..:

#include

Using namespace std;

int main ()

{

COUT << "Hello World! / N";

Return 0;

}

Hello.cpp

To test this bit of code, create a new folder by Typing The Following in The Visual C Toolkit 2003 Command Prompt Window:

Mkdir Hello

Navigate to the hello folder by Typing:

CD Hello

Now this you're in the hello folder, create a new hello.cpp file by Typing:

Notepad Hello.cpp

Notepad will open and you'll be prompted to create the new file. Type or paste the code from the Hello.cpp listing into Notepad. Click File, then Save in Notepad and then go back to the Visual C Toolkit 2003 Command Prompt window and TYPE: CL Hello.cpp

You'll See a Number of Warnings and Messages That You Can Safely Ignore For Now. You Should See The Following Message At The end of the list:

Microsoft (R) Incremental Linker Version 7.10.3077

CopyRight (c) Microsoft Corporation. All Rights Reserved.

/out:herlo.exe

Hello.obj

This message indicates that Hello.cpp was compiled into hello.obj and that it was linked to the appropriate C libraries to create the Hello.exe application. You can test the Hello.exe application by typing hello at the command prompt. You should see The Following Message.

C: / Program Files / Microsoft Visual C Toolkit 2003 / Hello> Hello

Hello World!

Earlier I mentioned that you may have seen some warnings when you compile the application, including a warning about the C exception handler and whether unwind semantics are enabled. I'm not going to cover that specific topic in this article, but you can specify the / EHSC Command Line Option In Your Compile Command To Specify The Synchronous Exception Handling Model and To Make The Messages Go Away:

CL / EHSC Hello.cpp

Now That You Have The Visual C Toolkit 2003 Command Prompt Window Open, Take a Look At The Number of Options Available with the Visual C Compiler. To Get The List, Run The Compiler with the / help option.

CL / HELP

The large list of options is common for modern C compilers and it should give you some indication of how complex the compiler is. You can get more information about the compiler options on the Visual C Compiler Options page.Now that you've seen how to build and run a very simple application using the Visual C Toolkit 2003, you should be able to build and test any of the examples that you might find in an introductory C book. Here are a few introductory books that I would suggest reading if you ' RE VERY New TO C :

Stan Lippman and Josee Lajoie, C Primy Randy Davis, C for Dummies Harvey M. Deitel and Paul J. Deitel, C : How to Program

If you already have a programming background and you want to get a found start with c , I Would Suggest Essential C by Stan Lippman.

You can continue to explore the Visual C Toolkit 2003 by reading the excellent articles written by Kate Gregory, which are included with the toolkit. These articles are also available online from the MSDN toolkit home page.

This is the first of what might turn out to be a number of articles that explain how to use the Visual C Toolkit 2003 to explore C . Please feel free to drop me a note at brianjo@microsoft.com with comments about this article and with Suggestions for other articles That You Would Like to See on this Topic.

转载请注明原文地址:https://www.9cbs.com/read-90962.html

New Post(0)