GCC (GNU Compiler Collection, GNU Compiler Suite), is a set of GNU developed by the programming language compiler. It is a free software released by the GPL and LGPL licenses and a key part of the GNU program and is the standard compiler for free Unix and Apple Mac OS X operating systems. GCC (especially the C language compiler) is also often considered a de facto standard for cross-platform compilers.
Example code: hello.c
gcc hello.c -o hello
In essence, the compilation process is divided into four stages, namely Preprocessing, Compilation, Assembly, and Linking.
gcc’s -E option allows the compiler to stop after preprocessing and output the preprocessing results. In this case, the result of the preprocessing is to insert the contents of the stdio.h file into hello.c.
After preprocessing, you can compile the generated hello.i file directly and generate the assembly code:
gcc -S hello.i -o hello.s
-S Compile only; do not assemble or link
-o Place the output into
For the assembly code file test.s generated in the previous section, the gas assembler is responsible for compiling it as an object file, as follows:
gcc -c hello.s -o hello.o
The gcc connector is provided by gas and is responsible for linking the target file of the program to all the additional target files needed to eventually generate the executable file. Additional target files include static link libraries and dynamic link libraries.
For the hello.o generated in the previous section, connect it to the C standard input and output library, and finally generate the hello program
gcc hello.o -o hello
The Compile process
g++ -E hello.cpp -o hello.i
g++ -S hello.i -o hello.s
g++ -c hello.s -o hello.o
g++ hello.o -o hello
The post How to Use GCC/G++ compiler: Pre-Processing,Compiling,Assembling,Linking appeared first on Penetration Testing.