How to Use GCC/G++ compiler: Pre-Processing,Compiling,Assembling,Linking – Penetration Testing

Gcc

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.

Usage

Example code: hello.c

#include
int main()
{
printf(“hello world!\n”);
return 0;
}

Compile

gcc hello.c -o hello
./hello

In essence, the compilation process is divided into four stages, namely Preprocessing, Compilation, Assembly, and Linking.

Preprocessing

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.

Compilation

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

Assembly

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

Linking

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

G++

The Compile process

Pre-Processing

g++ -E hello.cpp -o hello.i

Compiling

g++ -S hello.i -o hello.s

Assembling

g++ -c hello.s -o hello.o

Linking

g++ hello.o -o hello

The post How to Use GCC/G++ compiler: Pre-Processing,Compiling,Assembling,Linking appeared first on Penetration Testing.

http://ift.tt/2uqO3Xj http://ift.tt/2aM8QhC

Anúncios

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s