理解g++、GCC、GDB、GNU以及各种后缀

  • language translate

    There are 4 phases for a Program to finally get translated into an executable file viz:

    1. Preprocessing : It expands the code (For example - expansion of macros, removal of comments and conditional compilation)
    2. Compilation : Translates the code into assembly language, which an assembler can understand
    3. Assembly : Assembler translates the code into machine code or byte code
    4. Linking : It links various modules of the code, i.e. the function calls and finally delivers the executable
  • Compiler VS. Interpreter

    Compiler : Scans the entire program and translates it as a whole into machine code. It continues translating the program until the first error is met, in which case it stops. Hence debugging is easy. For example Java.

    Interpreter : Translates program one statement at a time and does not generate Object Code. It gives error only after scanning the entire program. For example Python.

  • GUN

    GUN, recursive acronym for “GUN’s Not Unix”, is a Unix-like operating system and free software under General Public License(GPL). It is intended to develop and share software for free, for all its users.

  • GCC

    GCC(GNU Compiler Collection) is a compiler system produced by the GNU Project under General Puublic License, supports various programming languages.

    Earlier it was named GNU C Compiler as it only supported C programming language. GCC can compile both C and C++ files(for example .c/.cpp files).

    It provides various options, for example:

    • -o Option (to specify the output name for the executable)
    • -wall Option(to enable warnings)
    • -e Option (to produce preprocessor output)
    • -S Option (file would contain the assembly output)
    • -c Option (file would contain machine code)
    gcc sourcecode.c -o executable
    # The gcc will stop compiling the program after the hello.s file is generated
    gcc -S hello.c
    

    GNU project C and C++ compiler, a GNU compiler collection.

    gcc [options] file ...
    

    The whole list of gcc compiler commands and options:

    Optionsmeaning
    -pass-exit-codesExit with highest error code from a phase
    –helpDisplay this information
    –target-helpDisplay target specific command line options
    (Use ‘-v --help’ to display command line options of sub-processes)
    -dumpspecsDisplay all of the built in spec strings
    -dumpversionDisplay the version of the compiler
    -dumpmachineDisplay the compiler’s target processor
    -print-search-dirsDisplay the directories in the compiler’s search path
    -print-libgcc-file-nameDisplay the name of the compiler’s companion library
    -print-file-name=Display the full path to library
    -print-prog-name=Display the full path to compiler component
    -print-multi-directoryDisplay the root directory for versions of libgcc
    -print-multi-libDisplay the mapping between command line options and multiple library search directiories
    -print-multi-os-directoryDisplay the relative path to OS libraries
    -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 linker
    -save-tempsDo not delete intermediate files
    -pipeUse pipes rather than intermediate files
    -timeTime the execution of each sub process
    -specs=Override built-in specs with the contents of
    -std=Assume that the input sources are for
    -B Add to the compiler’s search paths
    -b Run gcc for target , if installed
    -V Run gcc version number , if installed
    -vDisplay the programs invoked by the compiler
    -###Like -v but options quoted and commands not executed
    -EPreprocess only; do not compile, assemble or link
    -SCompile only; do not assemble or link
    -cCompile 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 file’s 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.

    If you have more object files to be linked together during the linking process, it is better to create the makefile.

  • g++

    To compile C++ codes you may use the g++, g++ accepts mostly the same options as gcc.

    G++ (GNU C++ Compiler) is a GUN C++ compiler invocation command, which is used for preprocessing, cimpilation, assembly and linking of source code to generate an executable file. It provides a similar set of options as defined for GCC to get output invarious intermediate stages of code compilation.

    g++ -o main.exe hello.cpp 
    
  • GDB debugger

    GNU Debugger (GDB) is a portable debugging tool for C and many other programming languages and runs on Unix-like operating systems.

    This tool comes in handy when our C program crashes and to know what exactly wrong has happened inside the code.

    GUN Debugger executes on the binary files/executables. It provides a GDB prompt which opens after typing gdb in your Linux terminal, where you can operate it using the commands it provides.

    Some commands that GDB provides:

    • r (run) — to execute the program from start till the very end.
    • b (break) — provides breakpoint on a particular line to debug the code.
    • disable — to disable a breakpoint.
    • enable — to enable a disabled breakpoint.
    • n (next) — go to next line of code, not into functions.
    • step — go to next instruction, diving into functions.
    • l (list) — displays the code.
    • p (print) — to display the stored value.
    • q (quit) — to exit the GDB prompt.
    • clear — clears all breakpoints.
    • continue — continues normal execution of code.
  • 各类后缀名

    Typically, the executable doesn’t have extension.

    File extensionDescription
    file_name.cC source code which must be preprocessed
    file_name.iC source code which should not be preprocessed
    file_name.iiC++ source code which should not be preprocessed
    file_name.hC header file (not to be compiled or linked)
    file_name.cc
    file_name.cp
    file_name.cxx
    file_name.cpp
    file_name.c++
    file_name.C
    C++ source code which must be preprocessed. For file_name.cxx, the xx must both be literally character x and file_name.C, is capital c.
    file_name.sAssembler code
    file_name.SAssembler code which must be preprocessed
    file_name.oObject file by default, the object file name for a source file is made by replacing the extension .c,.i,.s etc with .o
  • Reference

  1. GNU, GCC, G++, GDB — What are these terms? Explained!!
  2. gcc/g++常用编译选项和gdb常用调试命令
  3. MODULE 000-1 GCC, G++, GDB AND FRIENDS 1
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值