Linux系统编程-2.ppt
《Linux系统编程-2.ppt》由会员分享,可在线阅读,更多相关《Linux系统编程-2.ppt(56页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、7/23/2022Linux及编程2GNU CCvGCC的特性的特性面向多种语言面向多种语言 C,C+,Objective C,Pascal,Ada,Fortran能够对编译过程有更多的控制能够对编译过程有更多的控制可以控制嵌入在二进制执行文件中调试代码的数量和类型可以控制嵌入在二进制执行文件中调试代码的数量和类型可以优化执行代码可以优化执行代码有有30多个警告和多个警告和3个一般警告级个一般警告级可以进行交叉编译可以进行交叉编译对对C和和C+进行了大量扩展进行了大量扩展7/23/2022Linux及编程3GNU CCvC程序的编译过程程序的编译过程源代码源代码*.c预处理器(预处理器(cpp
2、)编译器编译器(cc) 目标代码目标代码*.o链接器(链接器(ld)可执行文件可执行文件头文件头文件*.h库代码库代码引导代码引导代码7/23/2022Linux及编程4GNU CCv实例实例7/23/2022Linux及编程5GNU CCv实例实例在预处理后停止编译过程在预处理后停止编译过程7/23/2022Linux及编程6GNU CCv实例实例从指定的步骤开始编译从指定的步骤开始编译只编译不链接只编译不链接7/23/2022Linux及编程7GNU CCv对文件扩展名的解释对文件扩展名的解释For any given input file, the file name surfix de
3、termines what kind of compilation is done.file.cC source code which must be preprocessed.file.iC source code which should not be preprocessed.file.iiC+ source code which should not be preprocessed.file.hC or C+ header le to be turned into a precompiled header.file.cc, file.cp, file.cxx, file.cpp, fi
4、le.CPP, file.c+, file.C C+ source code which must be preprocessed. Note that in .cxx, the last two letters must both be literally x. Likewise, .C refers to a literal capital C.file.hh, file.HC+ header file to be turned into a precompiled header.file.sAssembler code.file.SAssembler code which must be
5、 preprocessed.7/23/2022Linux及编程8GNU CCv常用的命令行选项常用的命令行选项-x languageSpecify explicitly the language for the following input files (rather than letting the compiler choose a default based on the file name suffix). This option applies to all following input files until the next -x option. Possible value
6、s for language are: vcc-headercpp-outputvc+c+-headerc+-cpp-outputvassemblerassembler-with-cpp-x noneTurn off any specification of a language, so that subsequent files are handled according to their file name suffixes (as they are if -x has not been used at all).7/23/2022Linux及编程9GNU CCv常用的命令行选项常用的命令
7、行选项-x和下述几个选项结合实现分步编译和下述几个选项结合实现分步编译 -cCompile or assemble the source files, but do not link. -SStop after the stage of compilation proper; do not assemble. -EStop after the preprocessing stage; do not run the compiler proper. -o filePlace output in file file. vIf -o is not specified, the default is
8、to put an executable le in a.out, the object file for source.suffix in source.o, its assembler file in source.s, and all preprocessed C source on standard output.-vPrint (on standard error output) the commands executed to run the stages of compilation. -#Like -v except the commands are not executed
9、and all command arguments are quoted. This is useful for shell scripts to capture the driver-generated command lines.Note that some combinations (for example, -x cpp-output -E) instruct gcc to do nothing at all.7/23/2022Linux及编程10GNU CCv常用的命令行选项常用的命令行选项下述选项控制下述选项控制C(C+)的的“方言方言” -ansiIn C mode, suppo
10、rt all ISO C89 programs. In C+ mode, remove GNU extensions that conflict with ISO C+.-std=Determine the language standard.vc89,iso9899:1990ISO C90 (same as -ansi).viso9899:199409ISO C90 as modied in amendment 1.vc99,c9x,iso9899:1999,iso9899:199xISO C99. vgnu89Default, ISO C90 plus GNU extensions (in
11、cluding some C99 features).vgnu99,gnu9xISO C99 plus GNU extensions. When ISO C99 is fully implemented in GCC, this will become the default. The name gnu9x is deprecated.vc+98The 1998 ISO C+ standard plus amendments.vgnu+98The same as -std=c+98 plus GNU extensions. This is the default for C+ code.7/2
12、3/2022Linux及编程11GNU CCv常用的命令行选项常用的命令行选项警告信息警告信息 Can request many specific warnings with options beginning W.-fsyntax-onlyCheck the code for syntax errors, but dont do anything beyond that.-pedanticIssue all the warnings demanded by strict ISO C and ISO C.-pedantic-errorsLike -pedantic, except that e
13、rrors are produced rather than warnings.-wInhibit all warning messages.-Wchar-subscriptsWarn if an array subscript has type char.-WcommentWarn whenever 注释嵌套注释嵌套.-WformatCheck calls to printf and scanf, etc., to make sure that the arguments supplied have types appropriate to the format string specifi
14、ed, and that the conversions specified in the format string make sense.7/23/2022Linux及编程12GNU CCv常用的命令行选项常用的命令行选项警告信息警告信息-WnonnullEnable warning about passing a null pointer for arguments marked as requiring a non-null value by the nonnull function attribute.-Wimplicit-intWarn when a declaration doe
15、s not specify a type.-Wimplicit-function-declaration-Werror-implicit-function-declarationGive a warning (or error) whenever a function is used before being declared.-WmainWarn if the type of main is suspicious.-Wmissing-bracesWarn if an aggregate or union initializer is not fully bracketed. For exam
16、ple, int a22 = 0, 1, 2, 3 .-WparenthesesWarn if parentheses are omitted in certain contexts, such as when there is an assignment in a context where a truth value is expected. E.g. if(a=2) .7/23/2022Linux及编程13GNU CCv常用的命令行选项常用的命令行选项警告信息警告信息-Wreturn-typeWarn whenever a function is defined with a retur
17、n-type that defaults to int.-WswitchWarn whenever a switch statement has an index of enumeral type and lacks a case for one or more of the named codes of that enumeration.-Wswitch-defaultWarn whenever a switch statement does not have a default case.-Wunused-functionWarn whenever a static function is
18、 declared but not defined or a non-inline static function is unused.-Wunused-labelWarn whenever a label is declared but not used.-Wunused-parameterWarn whenever a function parameter is unused aside from its declaration.-Wunused-variableWarn whenever a local variable or non-constant static variable i
19、s unused aside from its declaration.-WunusedAll the above -Wunused options combined.7/23/2022Linux及编程14GNU CCv常用的命令行选项常用的命令行选项警告信息警告信息-WuninitializedWarn if an automatic variable is used without rist being initialized or if a variable may be clobbered by a set jmp call.-WallAll of the above -W optio
20、ns combined.-Wsystem-headersPrint warning messages for constructs found in system header files.-Wfloat-equalWarn if floating point values are used in equality comparisons.-Wundef Warn if an undefined identifier is evaluated in an #if directive.-Wunreachable-codeWarn if the compiler detects that code
21、 will never be executed.-Winline Warn if a function can not be inlined and it was declared as inline.-WerrorMake all warnings into errors.7/23/2022Linux及编程15GNU CCv常用的命令行选项常用的命令行选项警告信息的实例警告信息的实例有问题的源程序有问题的源程序7/23/2022Linux及编程16GNU CCv常用的命令行选项常用的命令行选项警告信息的实例警告信息的实例默认的编译过程默认的编译过程7/23/2022Linux及编程17GNU
22、 CCv常用的命令行选项常用的命令行选项警告信息的实例警告信息的实例找出找出printf格式的编译过程格式的编译过程7/23/2022Linux及编程18GNU CCv常用的命令行选项常用的命令行选项警告信息的实例警告信息的实例找出找出比较使用了附值和注释嵌套比较使用了附值和注释嵌套的编译过程的编译过程7/23/2022Linux及编程19GNU CCv常用的命令行选项常用的命令行选项警告信息的实例警告信息的实例找出找出变量为初始化变量为初始化的编译过程的编译过程7/23/2022Linux及编程20GNU CCv常用的命令行选项常用的命令行选项调试选项调试选项-gProduce debugg
23、ing information in the operating systems native format (stabs, COFF, XCOFF, or DWARF). GDB can work with this debugging information.-ggdbProduce debugging information for use by GDB.-ftime-reportMakes the compiler print some statistics about the time consumed by each pass when it finishes.-fmem-repo
24、rtMakes the compiler print some statistics about permanent memory allocation when it finishes.7/23/2022Linux及编程21GNU CCv常用的命令行选项常用的命令行选项调试选项调试选项-O-O1Optimizing compilation takes somewhat more time, and a lot more memory for a large function. With -O, the compiler tries to reduce code size and execut
25、ion time, without performing any optimizations that take a great deal of compilation time.-O2Optimize even more.-O3Optimize yet more.-O0Do not optimize. This is the default.-OsOptimize for size.7/23/2022Linux及编程22GNU CCv常用的命令行选项常用的命令行选项控制预处理的选项控制预处理的选项-D name Predefine name as a macro, with definiti
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Linux 系统 编程
限制150内