Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please provide explanation What happens behind the scenes when you run \"gcc mai

ID: 3827654 • Letter: P

Question

Please provide explanation

What happens behind the scenes when you run "gcc main.c" on a Linux terminal? Compilation rightarrow Assembling rightarrow Loading rightarrow Linking Preprocessing rightarrow Compilation rightarrow Assembling rightarrow Linking rightarrow Loading Preprocessing rightarrow Compilation rightarrow Assembling rightarrow Linking Loading rightarrow Preprocessing rightarrow Assembling rightarrow Compilation rightarrow Linking Compilation rightarrow Linking rightarrow Assembling rightarrow Preprocessing

Explanation / Answer

the answer is :

preprocessing - compilation - assembling - linking

Explanation --

1. Preprocessing
During compilation of a C program the compilation is started off with preprocessing the directives (e.g., #include and #define). The preprocessor (cpp - c preprocessor) is a separate program in reality, but it is invoked automatically by the compiler. For example, the #include <stdio.h> command in line 1 of helloworld.c tells the preprocessor to read the contents of the system header file stdio.h and insert it directly into the program text.

2. Compilation
In this phase compilation proper takes place. The compiler (ccl) translates helloworld.i into helloworld.s. File helloworld.s contains assembly code. You can explicitly tell gcc to translate helloworld.i to helloworld.s by executing the following command.

[root@host ~]# gcc -S helloworld.i

3. Assembly
Here, the assembler (as) translates helloworld.s into machine language instructions, and generates an object file helloworld.o. You can invoke the assembler at your own by executing the following command.

[root@host ~]# as helloworld.s -o helloworld.o

4. Linking
This is the final stage in compilation of "Hello World!" program. This phase links object files to produce final executable file. An executable file requires many external resources (system functions, C run-time libraries etc.). Regarding our "Hello World!" program you have noticed that it calls the printf function to print the 'Hello World!' message on console. This function is contained in a separate pre compiled object file printf.o, which must somehow be merged with our helloworld.o file. The linker (ld) performs this task for you. Eventually, the resulting file helloworld is produced, which is an executable. This is now ready to be loaded into memory and executed by the system.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote