当前位置:编程学习 > C/C++ >>

学习windows编程(3)—hello.c的疑惑


上一篇,我们问了几个问题,这一篇就从hello.c的各个方面来研究研究,等到这一篇的结束来看这些疑惑有哪些是可以解答了的,当然还有一些可能要放到后面解决了……。

既然要抽丝剥茧,就要从手头已有的线索出发,同时加上搜索到的知识,以及自己的思考,任何问题的解决都是通过这个路径(当然,老板除外,老板这种生物只需要发出指令,然后得到结果就OK了……)。

我们现在有的,是一个hello.c文件,通过cl命令就可以生成目标hello.exe文件。

那我们就可以研究一下cl这个东西。

CL解释

CL.EXE(或cl.exe,似乎windows的文件系统对于大小写是不敏感的),是何许人也呢?直接引用微软的说辞吧。

CL.exe is a 32-bit tool that controls the Microsoft C and C++ compilers and linker. The compilers produce Common Object File Format (COFF) object (.obj) files. The linker produces executable (.exe) files or dynamic-link libraries (DLLs).

Note that all compiler options are case sensitive.

To compile without linking, use /c.

因为VC6的版本说明没有找到,这里的说明文字是Visual studio 2003的CL.EXE说明,不过都是一样的。从上面的说明可以看到CL是用来控制微软C和C++编译器(compiler)和链接器(linker),一共做了两件事情。编译器会生成COFF文件格式的目标文件(.obj);链接器会生成可执行文件(.exe)或者动态链接库文件(DLLs)。

对比我们之前的做法,的确是执行cl命令之后,生成了一个hello.obj文件和一个hello.exe文件。

另外在最后,还说明了一下,使用/c选项,则可以不进行链接过程。

CL选项

那cl还有哪些选项呢?使用cl /?来看看。

 1 d: est>cl /? 2 Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86 3 Copyright (C) Microsoft Corp 1984-1998. All rights reserved. 4  5                           C/C++ COMPILER OPTIONS 6  7                               -OPTIMIZATION- 8  9  /O1 minimize space                       /Op[-] improve floating-pt consistency10  /O2 maximize speed                       /Os favor code space11  /Oa assume no aliasing                   /Ot favor code speed12  /Ob<n> inline expansion (default n=0)    /Ow assume cross-function aliasing13  /Od disable optimizations (default)      /Ox maximum opts. (/Ogityb1 /Gs)14  /Og enable global optimization           /Oy[-] enable frame pointer omission15  /Oi enable intrinsic functions16 17                              -CODE GENERATION-18 19  /G3 optimize for 80386                   /Gy separate functions for linker20  /G4 optimize for 80486                   /Ge force stack checking for all funcs21  /G5 optimize for Pentium                 /Gs[num] disable stack checking calls22 /G6 optimize for Pentium Pro             /Gh enable hook function call23 /GB optimize for blended model (default) /GR[-] enable C++ RTTI24 /Gd __cdecl calling convention           /GX[-] enable C++ EH (same as /EHsc)25 /Gr __fastcall calling convention        /Gi[-] enable incremental compilation26 /Gz __stdcall calling convention         /Gm[-] enable minimal rebuild27 /GA optimize for Windows Application     /EHs enable synchronous C++ EH28 /GD optimize for Windows DLL             /EHa enable asynchronous C++ EH29 30 /Gf enable string pooling                /EHc extern "C" defaults to nothrow31 /GF enable read-only string pooling      /QIfdiv[-] enable Pentium FDIV fix32 /GZ enable runtime debug checks          /QI0f[-] enable Pentium 0x0f fix33 34                               -OUTPUT FILES-35 36 /Fa[file] name assembly listing file     /Fo<file> name object file37 /FA[sc] configure assembly listing       /Fp<file> name precompiled header file38 /Fd[file] name .PDB file                 /Fr[file] name source browser file39 /Fe<file> name executable file           /FR[file] name extended .SBR file40 /Fm[file] name map file41 42                               -PREPROCESSOR-43 44 /C dont strip comments                  /FI<file> name forced include file45 /D<name>{=|#}<text> define macro         /U<name> remove predefined macro46 /E preprocess to stdout                  /u remove all predefined macros47 /EP preprocess to stdout, no #line       /I<dir> add to include search path48 /P preprocess to file                    /X ignore "standard places"49 50                                 -LANGUAGE-51 52 /Zi enable debugging information         /Zl omit default library name in .OBJ53 /ZI enable Edit and Continue debug info  /Zg generate function prototypes54 55 /Z7 enable old-style debug info          /Zs syntax check only56 /Zd line number debugging info only      /vd{0|1} disable/enable vtordisp57 /Zp[n] pack structs on n-byte boundary   /vm<x> type of pointers to members58 /Za disable extensions (implies /Op)     /noBool disable "bool" keyword59 /Ze enable extensions (default)60 61                               -MISCELLANEOUS-62 63 /?, /help print this help message        /V<string> set version string64 /c compile only, no link                 /w disable all warnings65 /H<num> max external name length         /W<n> set warning level (default n=1)66 /J default ch

补充:软件开发 , C语言 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,