CSDN博客

img huyoo

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

发表于2004/9/23 0:43:00  3969人阅读

分类: 所需资料

如何在命令行下编译创建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
0 0

相关博文

我的热门文章

img
取 消
img