VC2005绿色编译器--命令行下编译C++代码
有人学了三个月没写过helloworld;有人不知道编译器是什么;有人第一个helloworld编译一下,数百个ERROR,自信心失去一大半.
学习c++,想试验一下习题,不知道如何入手,你还在IDE里面重复新建工程,然后产生一大片垃圾文件吗.
其实还有另外一种编译方式:
那就是传说中的记事本加命令行编译.只要你有U盘,只有装windows的电脑,就可以写代码了.
一.首先你要有Platform SDK
WIN7 Windows SDKS微软官方下载页
1.GRMSDK_EN_DVD.iso X86(32bit)
2.GRMSDKIAI_EN_DVD.iso I64(Itanium)
3.GRMSDKX_EN_DVD.iso AMD64(64bit)
二.安装完,然后在安装的根目录(含有PlatformSDK,lib,include目录)下新建一个cmd文件内容如下 (以VC8.0为例)
@echo off
@prompt $h
@title NewVS2005SP1-C/C++MODE
color f5if "#%vc2005dir_defined%"=="#" (set vc2005dir=%cd%&& set vc2005dir_defined=true)
if "#%path0_defined%"=="#" (set path0=%path% && set path0_defined=true ) @echo.
@echo ******** 欢迎进入C/C++编译模式**********
@echo ┏┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┓
@echo ┋ VC 2005 编译器 ┋
@echo ┋ -------------------------------------- ┋
@echo ┋ rc.exe:资源编译器 ┋
@echo ┋ ml.exe:宏汇编编译器 ┋
@echo ┋ cl.exe:C/C++编译器 ┋
@echo ┋ link.exe:链接器 ┋
@echo ┋ lib.exe:库生成器 ┋
@echo ┋ nmake.exe:(makefile)程序维护实用工具 ┋
@echo ┗┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┛
@set PATH=%path0%;%vc2005dir%\bin;%vc2005dir%\PlatformSDK\Bin;%vc2005dir%\myTOOL\windbg\
@set INCLUDE=%vc2005dir%\include;%vc2005dir%\PlatformSDK\Include;%vc2005dir%\atlmfc\include;%vc2005dir%\DirectX_SDK\Include;%vc2005dir%\WTL\Include
@set LIB=%vc2005dir%\lib;%vc2005dir%\PlatformSDK\Lib;%vc2005dir%\atlmfc\lib;%vc2005dir%\DirectX_SDK\Lib\x86;
rem 设置调试符号路径
@set _NT_SYMBOL_PATH=%vc2005dir%\myTOOL\windbg\symbols
@echo VC2005所在根目录是%vc2005dir%
@echo (若上面目录不正确将不能正确配置环境变量path,include,lib)
@echo 请以 cd /d 命令转至源程序目录,然后开始编译等工作
echo.
PROMPT -
if "#%once_defined%"=="#" ( set once_defined=true&&%comspec% /k)
运行效果是这样子的
敲入CL /? LINK /?确定是否正确
3.每次敲命令是不是很烦,应该还有另一种方式生成目标,新建一文档Create_VC_UNICODE_v2.0.CMD,然后添加VC路径
if exist D:\software\DevKit\VC set vc2005dir=D:\software\DevKit\VC
@title VC8.0命令行生成WIN32,UNICODE,RELEASE版
@rem by wisepragma
@PROMPT -@ECHO off
@echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rem color 0a
color f6
rem 在这里配置vc的根目录
if exist D:\软件\VC8.0NEW set vc2005dir=D:\软件\VC8.0NEW
if exist D:\software\DevKit\VC set vc2005dir=D:\software\DevKit\VC@set PATH=%path%;%vc2005dir%\bin;%vc2005dir%\PlatformSDK\Bin;%vc2005dir%\myTOOL\windbg\;%vc2005dir%\myTOOL\leakdiag
@set INCLUDE=%vc2005dir%\include;%vc2005dir%\PlatformSDK\Include;%vc2005dir%\atlmfc\include;%vc2005dir%\DirectX_SDK\Include;%vc2005dir%\WTL\Include
@set LIB=%vc2005dir%\lib;%vc2005dir%\PlatformSDK\Lib;%vc2005dir%\atlmfc\lib;%vc2005dir%\DirectX_SDK\Lib\x86;rem 不要有空格或中文,会出错,有乱码rem 取当前目录名作为程序名
for %%i in (.) do set outfile=%%~ni
rem set outfile=color
set outdir=.\
set cedir=temp
set cd0=%cd%@echo 正在清除垃圾...>>nul del /f /s /q cl_set.rsp link_set.rsp rc_set.rsp *.res *.idb *.pdb *.obj *.exp *.exe.embed.manifest *.exe.intermediate.manifest *.ncb *.user *.pch *.ilk *.dep BuildLog.htm *.rc2taskkill.exe /im %outfile%.exe
del /f /s /q %outfile%.exemd "%outdir%"@echo ++++++++++Compiling and linking+++++++++++++++++++++++++++++++++++++
@echo 正在编译资源...
for %%x in (*.rc) DO rc /v %%x@echo 正在编译源文件...
rem /D "_ATL_MIN_CRT" 会产生ERROR:LNK2005 XXX已经在 atlmincrt.lib(atlinit.obj) 中定义
>cl_set.rsp echo /O1 /FD /MT /D "NDEBUG" /D "STRICT" /D "WIN32" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /EHsc /fp:fast /GR- /W3 /c /TP /Os /Fo"%outdir%/"
>>cl_set.rsp dir /b *.cpp
cl @cl_set.rsp /W3 /nologo @echo 链接正进中...
>link_set.rsp echo "/OUT:%outfile%.exe" /INCREMENTAL:NO /MANIFEST:NO /NODEFAULTLIB:"oldnames.lib" /STACK:65536,4096 /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
@rem /SUBSYSTEM:WINDOWS
>>link_set.rsp dir /b *.res *.obj
link @link_set.rsp /nologo /ERRORREPORT:PROMPT
@REM 判断if exist %outfile%.exe goto goahead:ABORT
rem COLOR 0c
rem color f0color f3
cd %cd0%%comspec% /k
:goahead
echo 清除中间垃圾...
del *.res *.obj *.rsp
@del /f /s /q *.aps *.idb *.pdb *.exp *.exe.embed.manifest *.exe.intermediate.manifest *.ncb *.user *.pch *.ilk *.dep BuildLog.htm *.rc2
echo ------准备运行--------
@echo on
%outfile%.exe
@rem start %outfile%.exe
@ECHO.
@%comspec% /k
到此我们就可以编译helloworld.cpp了
#include <iostream>
using namespace std;
int main()
{cout<<"hellowrold"<<endl;
}
将源文件单独放在新建的目录下,把Create_VC_UNICODE_v2.0.CMD也拷进入,双击CMD自动生成
再来个示例代码
//C++数值类型的取值范围
#include "stdio.h"
#include "iostream"
using namespace std;
int main()
{char a1=-128;//-128~+127
short b1=-32768;// -32768~+32767
int c1=-2147483648;//-2147483648~+2147483647
long d1=-2147483648;//-2147483648~+2147483647
long long x1=-9223372036854775808;//-9223372036854775808~9223372036854775807
//以下取-1转化后为最大值
unsigned char a2=-1;//0~255
unsigned short b2=-1;// 0~65535
unsigned int c2=-1;//0~4294967295
unsigned long d2=-1;//0~4294967295
unsigned long long x2=-1;//0~18446744073709551615
float e=100/3.0;//10e±38,6位有效数字-7
double f=100.0/3;//10e±308,12位有效数字-16
long double g=100.0/3;//10±4932,15位有效数字-16
cout.precision(50);
cout<<"测试平台:Intel P4,XPsp3-32bit,VC8.0"<<endl;
cout<<"浮点数精度测试100除以3"<<endl;
cout<<"float \t\t e="<<e<<endl;
cout<<"double \t\t f="<<f<<endl;
cout<<"long double \t g="<<g<<endl;
cout<<"有符号数取最小值分别是"<<endl;
printf("char a1 ->%d\n",a1);
cout<<"short b1 ="<<b1<<endl;
cout<<"int c1 ="<<c1<<endl;
cout<<"long d1 ="<<d1<<endl;
cout<<"long long x1 ="<<x1<<endl;
cout<<"....最低值再减一,溢出得最大值"<<endl;
a1--;b1--;c1--;d1--;x1--;
printf("char a1 ->%d\n",a1);
cout<<"short b1 ="<<b1<<endl;
cout<<"int c1 ="<<c1<<endl;
cout<<"long d1 ="<<d1<<endl;
cout<<"long long x1 ="<<x1<<endl;
cout<<"无符号数取最大值(-1)分别是"<<endl;
printf("unsigned char a2 ->%d\n",a2);
cout<<"unsigned short b2 ="<<b2<<endl;
cout<<"unsigned int c2 ="<<c2<<endl;
cout<<"unsigned long d2 ="<<d2<<endl;
cout<<"unsigned long long x2 ="<<x2<<endl;
cout<<"...最大值,加一后,溢出,归零(最小值)"<<endl;
a2++;b2++;c2++;d2++;x2++;
printf("unsigned char a2 ->%d\n",a2);
cout<<"unsigned short b2 ="<<b2<<endl;
cout<<"unsigned int c2 ="<<c2<<endl;
cout<<"unsigned long d2 ="<<d2<<endl;
cout<<"unsigned long long x2 ="<<x2<<endl;
cout<<"....零减一后,又溢出,得最大值,所以别拿无数号数和小于0比"<<endl;
a2--;b2--;c2--;d2--;x2--;
printf("unsigned char a2 ->%d\n",a2);
cout<<"unsigned short b2 ="<<b2<<endl;
cout<<"unsigned int c2 ="<<c2<<endl;
cout<<"unsigned long d2 ="<<d2<<endl;
cout<<"unsigned long long x2 ="<<x2<<endl;
cout<<"存储大小"<<endl;
cout<<"sizeof(char) ="<<sizeof(char)<<"字节" <<endl;
cout<<"sizeof(short) ="<<sizeof(short) <<"字节" <<endl;
cout<<"sizeof(int) ="<<sizeof(int)<<"字节" <<endl;
cout<<"sizeof(long) ="<<sizeof(long )<<"字节" <<endl;
cout<<"sizeof(long long) ="<<sizeof(long long)<<"字节" <<endl<<endl;
cout<<"sizeof(unsigned char) ="<<sizeof(unsigned char)<<"字节" <<endl;
cout<<"sizeof(unsigned short) ="<<sizeof(unsigned short )<<"字节" <<endl;
cout<<"sizeof(unsigned int) ="<<sizeof(unsigned int )<<"字节" <<endl;
cout<<"sizeof(unsigned long) ="<<sizeof(unsigned long )<<"字节" <<endl;
cout<<"sizeof(unsigned long long) ="<<sizeof(unsigned long long)<<"字节" <<endl<<endl;
cout<<"sizeof(float) ="<<sizeof(float )<<"字节" <<endl;
cout<<"sizeof(double) ="<<sizeof(double)<<"字节" <<endl;
cout<<"sizeof(long double) ="<<sizeof(long double )<<"字节" <<endl;
//其他方法#include "limits"//其他方法
/*cout<<"---------以下最大值--------------------"<<endl; cout<< numeric_limits<unsigned long long >::max() <<endl; cout<< numeric_limits< long long >::max() <<endl; cout<<"---------以下最小值--------------------"<<endl; cout<< numeric_limits<unsigned long long >::min() <<endl; cout<< numeric_limits<long long>::min() <<endl;
*/
//long long 取值-2E(sizeof(long long)*8)/2 ~ 2E(sizeof(long long)*8)-1
//unsigned long long 取值0~2E(sizeof(unsigned long long)*8)-1
return 0;
}
运行结果
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
正在清除垃圾...
找不到 H:\helloworld\新建文件夹\cl_set.rsp
错误: 没有找到进程 "新建文件夹.exe"。
删除文件 - H:\helloworld\新建文件夹\新建文件夹.exe
子目录或文件 .\ 已经存在。
++++++++++Compiling and linking+++++++++++++++++++++++++++++++++++++
正在编译资源...
正在编译源文件...
howwide.cpp
howwide.cpp(9) : warning C4146: 一元负运算符应用于无符号类型,结果仍为无符号类型
howwide.cpp(10) : warning C4146: 一元负运算符应用于无符号类型,结果仍为无符号类型
howwide.cpp(11) : warning C4146: 一元负运算符应用于无符号类型,结果仍为无符号类型
链接正进中...
清除中间垃圾...
删除文件 - H:\helloworld\新建文件夹\vc80.idb
------准备运行---------新建文件夹.exe
测试结果:
浮点数精度测试100除以3
float e=33.33333206176757800000000000000
double f=33.33333333333333600000000000000
long double g=33.33333333333333600000000000000
有符号数取最小值分别是
char a1 ->-128
short b1 =-32768
int c1 =-2147483648
long d1 =-2147483648
long long x1 =-9223372036854775808
....最低值再减一,溢出得最大值
char a1 ->127
short b1 =32767
int c1 =2147483647
long d1 =2147483647
long long x1 =9223372036854775807
无符号数取最大值(-1)分别是
unsigned char a2 ->255
unsigned short b2 =65535
unsigned int c2 =4294967295
unsigned long d2 =4294967295
unsigned long long x2 =18446744073709551615
...最大值,加一后,溢出,归零(最小值)
unsigned char a2 ->0
unsigned short b2 =0
unsigned int c2 =0
unsigned long d2 =0
unsigned long long x2 =0
....零减一后,又溢出,得最大值,所以别拿无数号数和小于0比
unsigned char a2 ->255
unsigned short b2 =65535
unsigned int c2 =4294967295
unsigned long d2 =4294967295
unsigned long long x2 =18446744073709551615
存储大小
sizeof(char) =1字节
sizeof(short) =2字节
sizeof(int) =4字节
sizeof(long) =4字节
sizeof(long long) =8字节sizeof(unsigned char) =1字节
sizeof(unsigned short) =2字节
sizeof(unsigned int) =4字节
sizeof(unsigned long) =4字节
sizeof(unsigned long long) =8字节sizeof(float) =4字节
sizeof(double) =8字节
sizeof(long double) =8字节-
VC2005绿色编译器--命令行下编译C++代码相关推荐
- linux中C编译命令,linux下命令行下编译c程式
linux下命令行下编译c程式 2008-02-23 05:41:36来源:互联网 阅读 () C 是任何版本的UNIX上的系统语言. C 在过去的二十年中有了很大的发展. 在80年代末期美国国家标准 ...
- 在cmd命令行下编译运行C/C++源文件
一直用java来写程序,java配置好jre路径之后,在cmd下编译运行,很方便. 刚好要给一个舍友改下C程序,想到可不可以像java一样在环境变量里配置好C的编译路径呢? 于是上网搜了一下,得到如下 ...
- Linux下编译build的命令,Linux命令行下编译Android NDK的示例代码
这几天琢磨写一个Android的Runtime用来加速HTML5 Canvas,让GameBuilder+CanTK 不但开发速度快,运行速度也能接近原生应用.所以花了点时间研究Android NDK ...
- 在win7命令行下编译运行C++程序
1.安装VS2010,我的系统是64位的,因此安装64位配置环境变量 2.配置环境变量,在系统-属性-高级系统设置里配置环境变量 1)配置cl编译器,在path中添加C:\Program Files ...
- JNI命令行下编译错误解决方案
第一步,找到你的android sdk路径 QQ截图20170612233945.png 第二步,加入到环境变量CLASSPATH QQ截图20170612234346.png 我的android s ...
- 命令行下编译Wordcount
1. 编辑WordCount.java文件,在下载的hadoop安装包里有WordCount的例子 http://mirrors.hust.edu.cn/apache/hadoop/common/ha ...
- android 能调用gcc_如何在命令行下使用Android NDK交叉编译工具
我们知道,在Linux下可以使用gcc来把一份C代码编译成为Linux上的可执行程序, 如: $ gcc -o main.out main.c 而Android平台提供了NDK工具包来交叉编译可以运行 ...
- 如何在命令行下使用Android NDK交叉编译工具
我们知道,在Linux下可以使用gcc来把一份C代码编译成为Linux上的可执行程序, 如: $ gcc -o main.out main.c 而Android平台提供了NDK工具包来交叉编译可以运行 ...
- 命令行下打包Qt程序
命令行下打包Qt程序 上一节我们说了 命令行下编译Qt程序 https://blog.csdn.net/weixin_42837024/article/details/81945656 现在基于上次继 ...
- win7C语言编译调试,如何在Windows的命令行下进行程序编译和gdb调试
作为软件工程的大学生,博主一开始在Windows下的开发环境就是简单的 dev c++ 而已.然而熟悉了Linux Ubuntu下的命令行编译和gdb调试的环境后,就极少使用dev了.这就有个问题,其 ...
最新文章
- JavaScript:事件冒泡和事件委托
- 2019年上半年收集到的人工智能自然语言处理方向干货文章
- python无限次输入_在Raspberry Pi上的Python用户输入无限循环内部输入时很多输入错过了输入...
- 【Deep Learning】Tensorflow实现线性回归
- Java NIO系列教程(十) Java NIO DatagramChannel
- 胰腺癌代谢生物标志物最新研究成果:诊断效率明显优于传统标志物
- java代码如何删除文件_Java如何删除文件和目录代码? 爱问知识人
- Android 第3方控件一览表
- multisim红绿灯元器件在哪里_实验一:Multisim交通灯仿真.ppt
- 基于QT和DCMTK的Dicom 图像浏览器---目录
- 计算多条线段总长的lisp程序_CAD二次开发-lisp篇(1)统计长度
- 【机器学习】Tensorflow:理解和实现快速风格化图像fast neural style
- 计算机的中央处理器CPU包括什么,中央处理器cpu由哪些组成 中央处理器的作用是什么...
- deep linux用ntfs,deepin开机挂载ntfs分区和ext4分区教程
- windows 批量 jpg 转 bmp 方法
- 成品APP直播源码HLS直播(M3U8)回看和下载功能的实现
- 关于1 problem (1 error, 0 warnings) 1 error and 0 warnings potentially fixable with the `--fix` 错误
- iOS Wow体验 - 第四章 - 为应用的上下文环境而设计
- 21 函数的凸性与拐点
- 数字化营销工具有哪些?数字化营销功能有哪些?