如何在命令行下编译创建VC程序



转贴自常州VC编程网 http://www.czvc.com/down.asp?id=94
大多数MS Visual C++创建的程序用VC编译器是很容易编译并创建出可执行文件的。但有时,你可能需要从命令提示行运行程序。这个例子将阐述如何用命令行编译创建VC程序。

VC默认安装成功后,并不具备能从命令行编译创建VC程序这一特征。我们必须做如下3步工作:

1 打开DOS命令提示符窗口。

2 在C盘根目录下输入:
CD Program Files/Microsoft Visual Studio/VC98/Bin
回车进入到如下目录:
C:/Program Files/Microsoft Visual Studio/VC98/Bin>

3 然后输入VCVARS32再回车,你可以看到如下信息:
C:/Program Files/Microsoft Visual Studio/VC98/Bin>VCVARS32
Setting environment for using Microsoft Visual C++ tools.
如图1:

图1


好了,至此相关设置完成,接下来我们将在命令行下编译创建一个VC程序:

1 打开VC,选择NEW,在工程属性页选择“Win32 Console Application”,这里我把它命名为AConsoleApp,
我的工程目录为:D:/MyProgram2/AConsoleApp,然后OK创建一个空的Win32控制台工程。

2 新建一个C++文档main.cpp,输入如下代码:
#include
using namespace std;

int main()
{
cout << "/nC++ is Fun!!!/n";
return 0;
}
保存所有文档,关闭工程。

3 打开DOS命令提示符窗口,使当前目录为D:/MyProgram2/AConsoleApp>,然后输入CL main.cpp,回车,可以看到如下信息:
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_ostream
t 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 std::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/AConsoleApp>


此时你可以发现目录D:/MyProgram2/AConsoleApp>下已经生成了可执行文件main.exe,您可以在命令行环境下执行它,输入main并回车,结果如下:
D:/MyProgram2/AConsoleApp>main

C++ is Fun!!!

D:/MyProgram2/AConsoleApp>

如图2:

图2

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值