您的位置 首页 5G

gcc的几个妙用

gcc的学习在C接触到linux以后就开始不断的学习,也知道了一些基本的用法,但是关于gcc的使用还是有很多值得我们加深的地方。gcc只是一个

gcc的学习在C接触到linux今后就开端不断的学习,也知道了一些根本的用法,可是关于gcc的运用仍是有许多值得咱们加深的当地。gcc 仅仅一个编译东西罢了。也就相当于咱们在windows环境下的visual c++等相同,区别是visual c++是根据IDE的,而gcc是这些IDE的根底。学习linux程序设计必然会学习gcc。

gcc本质是完结程序的编译和链接,程序的编译是指从一种文件类型转换到另一种文件类型的进程。一个C言语程序转换为可执行程序的根本进程如下:
1、编写程序(vi,emacs等软件)
2、程序预编译(cpp)
3、编译成汇编程序(cc)
4、汇编程序(as)
5、链接程序(ld)
其间的这些进程都现已被gcc包括,咱们在实践的编译进程中选用了gcc main.c -o main.exe即可完成一个程序的编译和链接。并不需求一步一步的完成,可是咱们在剖析的进程中又有必要留意一个C言语文件的处理进程以及相应的处理程序。
关于gcc的根本意义用法就不再具体的说明晰,我觉得最简略的运用方法是经过软件的help学习软件。
[gong@Gong-Computer test]$ gcc –help
Usage: gcc [options] file…
Options:
-pass-exit-codes Exit with highest error code from a phase
–help Display this information
–target-help Display target specific command line options
–help={target|optimizers|warnings|params|[^]{joined|separate|undocumented}}[,…]
Display specific types of command line options
(Use -v –help to display command line options of sub-processes)
–version Display compiler version information
-dumpspecs Display all of the built in spec strings
-dumpversion Display the version of the compiler
-dumpmachine Display the compilers target processor
-print-search-dirs Display the directories in the compilers search path
-print-libgcc-file-name Display the name of the compilers companion library
-print-file-name= Display the full path to library -print-prog-name= Display the full path to compiler component -print-multi-directory Display the root directory for versions of libgcc
-print-multi-lib Display the mapping between command line options and
multiple library search directories
-print-multi-os-directory Display the relative path to OS libraries
-print-sysroot Display the target libraries directory
-print-sysroot-headers-suffix Display the sysroot suffix used to find headers
-Wa, Pass comma-separated on to the assembler
-Wp, Pass comma-separated on to the preprocessor
-Wl, Pass comma-separated on to the linker
-Xassembler Pass on to the assembler
-Xpreprocessor Pass on to the preprocessor
-Xlinker Pass on to the linker
-combine Pass multiple source files to compiler at once
-save-temps Do not delete intermediate files
-save-temps= Do not delete intermediate files
-no-canonical-prefixes Do not canonicalize paths when building relative
prefixes to other gcc components
-pipe Use pipes rather than intermediate files
-time Time the execution of each subprocess
-specs= Override built-in specs with the contents of
-std= Assume that the input sources are for
–sysroot= Use as the root directory for headers
and libraries
-B Add to the compilers search paths
-b Run gcc for target , if installed
-V Run gcc version number , if installed
-v Display the programs invoked by the compiler
-### Like -v but options quoted and commands not executed
-E Preprocess only; do not compile, assemble or link
-S Compile only; do not assemble or link
-c Compile and assemble, but do not link
-o Place the output into
-x Specify the language of the following input files
Permissible languages include: c c++ assembler none
none means revert to the default behavior of
guessing the language based on the files extension
Options starting with -g, -f, -m, -O, -W, or –param are automatically
passed on to the various sub-processes invoked by gcc. In order to pass
other options on to these processes the -W options must be used.
For bug reporting instructions, please see:
.
从上面的成果能够知道根本的用法。
可是仍是有几个需求留意的当地,这也是咱们学习gcc时不常常运用,但又十分有用的几个用法。
1、选用gcc完成预编译,预编译能够完成代码的查看,特别是宏界说的查看,经过预编译查看实践的代码是否犯错,这是十分有用的查看方法。
因为预编译今后宏界说被扩展了,这时对源码的剖析就能找出代码宏界说等是否存在过错,特别时一些不容易发现的过错。
根本的完成方法为:gcc -E file.c > file.pre.c
[gong@Gong-Computer Example]$ vi main.c
选用重定向的方法改动输出流,便于查看过错地点。
[gong@Gong-Computer Example]$ gcc -E main.c > main.pre.c
[gong@Gong-Computer Example]$ vi main.pre.c
从上面的成果能够发现咱们的宏现已完成了扩展。经过剖析宏的扩展能够剖析代码是否正确。

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/yingyong/5g/317790.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部