-
language translate
There are 4 phases for a Program to finally get translated into an executable file viz:
- Preprocessing : It expands the code (For example - expansion of macros, removal of comments and conditional compilation)
- Compilation : Translates the code into assembly language, which an assembler can understand
- Assembly : Assembler translates the code into machine code or byte code
- 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:
Options meaning -pass-exit-codes Exit with highest error code from a phase –help Display this information –target-help Display target specific command line options
(Use ‘-v --help’ to display command line options of sub-processes)-dumpspecs Display all of the built in spec strings -dumpversion Display the version of the compiler -dumpmachine Display the compiler’s target processor -print-search-dirs Display the directories in the compiler’s search path -print-libgcc-file-name Display 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-directory Display the root directory for versions of libgcc -print-multi-lib Display the mapping between command line options and multiple library search directiories -print-multi-os-directory Display 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-temps Do not delete intermediate files -pipe Use pipes rather than intermediate files -time Time 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 -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 file’s extensionOptions 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 typinggdb
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 extension Description file_name.c C source code which must be preprocessed file_name.i C source code which should not be preprocessed file_name.ii C++ source code which should not be preprocessed file_name.h C 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.CC++ 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.s Assembler code file_name.S Assembler code which must be preprocessed file_name.o Object file by default, the object file name for a source file is made by replacing the extension .c
,.i
,.s
etc with.o
-
Reference
理解g++、GCC、GDB、GNU以及各种后缀
猜你喜欢
转载自blog.csdn.net/The_Time_Runner/article/details/107290576
今日推荐
周排行