How to build a VC program in the command line

xiaoxiao2021-03-06  57

How to build a VC program in the command line

Reposted from the state VC programming network

http://www.czvc.com/down.asp?id=94

Most MS Visual C creation programs are easy to compile and create executables with VC compilers. But sometimes you may need to operate the program from the command prompt. This example will explain how to create a VC program with a command line.

After the VC default installation is successful, there is no feature that can be created from the command line to create a VC program. We must do the following 3 steps:

1 Open the DOS command prompt window.

2 Enter: Enter in the root directory of the C:

CD Program Files / Microsoft Visual Studio / VC98 / BIN

Enter the following directory:

C: / Program Files / Microsoft Visual Studio / VC98 / BIN>

3 Then enter the VCVARS32 and then enter, you can see the following information:

C: / Program Files / Microsoft Visual Studio / VC98 / BIN> VCVARS32

Setting Environment for Using Microsoft Visual C Tools.

Figure 1:

figure 1

Ok, to this related settings, then we will build a VC program in the command line:

1 Open the VC, select New, select "Win32 Console Application" in the Engineering Properties page, here I name it as AconsoleApp,

My project catalog is: D: / myprogram2 / aconsoleapp, then OK creates an empty Win32 console project.

2 Create a C document main.cpp, enter the following code:

#include

Using namespace std;

int main ()

{

COUT << "/ NC is Fun !!! / N";

Return 0;

}

Save all documents and turn off the project.

3 Open the DOS command prompt window so that the current directory is d: / myprogram2 / aconsoleapp>, then enter Cl Main.cpp, enter, you can see the following information:

D: / myprogram2 / aconsoleapp> cl main.cpp

Microsoft (R) 32-Bit C / C Optimizing Compiler Version 12.00.8168 for 80x86

Copyright (c) Microsoft Corp 1984-1998. All Rights Reserved.

Main.cpp

C: / Program Files / Microsoft Visual Studio / VC98 / INCLUDE / ISTREAM (547): WARNING C45

30: C Exception Handler Used, But Unwind Semantics Are Not Enabled. Specify -g

X

C: / Program Files / Microsoft Visual Studio / VC98 / Include / Ostream (234): Warning C45

30: C Exception Handler Used, But Unwind Semantics Are Not Enabled. Specify -g

X

C: / Program Files / Microsoft Visual Studio / VC98 / Include / Ostream (229): WHI

Le Compiling Class-Template Member Function 'Class Std :: Basic_OStreamt std :: char_traits

> & __ thiscall std :: Basic_OSTREAM

Traits

> :: Put (char) '

C: / Program Files / Microsoft Visual Studio / VC98 / Include / Ostream (234): Warning C45

30: C Exception Handler Used, But Unwind Semantics Are Not Enabled. Specify -g

X

C: / Program Files / Microsoft Visual Studio / VC98 / Include / Ostream (229): WHI

Le Compiling Class-Template MEMBER FUNCTION 'CLASS std :: Basic_OStream

Hort, Struct st :: char_traits

> & __ thiscall std :: Basic_OSTREAM

Signed short, struct std :: char_traits

> :: PUT (Unsigned Short) '

C: / Program Files / Microsoft Visual Studio / VC98 / include / istream (46): Warning C453

0: C Exception Handler Used, But Unwind Semantics Are Not Enabled. Specify -gx

C: / Program Files / Microsoft Visual Studio / VC98 / Include / IStream (41): Whil

E Compiling class-template member function 'bool __thiscall std :: basic_istream

Har, Struct std :: char_traits

> :: IPFX (BOOL) '

C: / Program Files / Microsoft Visual Studio / VC98 / include / istream (46): Warning C453

0: C Exception Handler Used, But Unwind Semantics Are Not Enabled. Specify -gx

C: / Program Files / Microsoft Visual Studio / VC98 / Include / IStream (41): Whil

E Compiling class-template member function 'bool __thiscall std :: basic_istream

NSIGNED SHORT, STRUCT std :: char_traits

> :: IPFX (BOOL) '

C: / Program Files / Microsoft Visual Studio / VC98 / include / xstring (525): Warning C45

30: C Exception Handler Used, But Unwind Semantics Are Not Enabled. Specify -g

X

C: / Program Files / Microsoft Visual Studio / VC98 / include / xstring (521): WHI

Le compiling class-template member function 'void __thiscall std :: Basic_String

Har, Struct Std :: Char_Traits, Class Std :: allocator

> :: _ Copy (unsigned i

NT) '

C: / Program Files / Microsoft Visual Studio / VC98 / Include / Ostream (296): Warning C45

30: C Exception Handler Used, But Unwind Semantics Are Not Enabled. Specify -g

X

Main.cpp (6): See Reference To Function Template Instantiation 'Class ST

D :: Basic_OStream

> & __ cdecl std :: operator << (

Class std :: Basic_OStream

> &, const char *) 'B

EING Compiled

Microsoft (R) Incremental Linker Version 6.00.8168

Copyright (c) Microsoft Corp 1992-1998. All Rights Reserved.

/out:main.exe

Main.obj

D: / myprogram2 / aconsolaapp>

At this point, you can find the directory D: / myprogram2 / aconsoleapp> already generated on the executable file.exe, you can execute it in the command line environment, enter main and enter, and the results are as follows:

D: / myprogram2 / aconsoleapp> main

C is fun !!!

D: / myprogram2 / aconsolaapp>

Figure 2:

figure 2

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

New Post(0)