Rento

The recession may be over in the United States, but the values that emerged during it appear to be staying put — and the sharing economy is giving new weight to the axiom “less is more.” 78% of…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Inside the compilation process

What happens when you type gcc main.c

There are four phases for a C program to become an executable:

The preprocessor or cpp is the macro preprocessor for the c computer programming languages.the preprocessor provides the ability for the inclusion of header files,macro expansions ,conditional compilation ,and line control.In many C implementations it is a separate program invoked by the compiler as the first part of translation.The language of preprocessor directives is only weakly related to the grammar of C ,abd so is sometimes used to process other kinds of text files

The second stage of compilation is confusingly enough called compilation.In this stage, the preprocessed code is translated to assembly instructions specific to the target processor architecture. These form an intermediate human readable language. The existence of this step allows for C code to contain inline assembly instructions and for different assemblers to be used. To save the result of the compilation stage, pass the -S option “gcc -s main.c”

This will create a file named main.c , containing the generated assembly instructions.

During this stage, an assembler is used to translate the assembly instructions to object code. The output consists of actual instructions to be run by the target processor.To save the result of the assembley stage ,pass the c option

“gcc -c main.c”

The job of the linker is to link together a bunch of object files (.o files) into a binary executable. This includes both the object files that the compiler created from your source code files as well as object files that have been pre-compiled for you and collected into library files. These files have names which end in .a or .so, and you normally don’t need to know about them, as the linker knows where most of them are located and will link them in automatically as needed.

Like the preprocessor, the linker is a separate program called ld. Also like the preprocessor, the linker is invoked automatically for you when you use the compiler. The normal way of using the linker is as follows:

“gcc main1.o main2.o main3.o -o main”

This line tells the compiler to link together three object files (main1.o,main2.o and main3.o) into a binary executable file named main that you can run.

Add a comment

Related posts:

For Those Failing To Succeed

The combination of two things made me feel useless: watching The Founder on Netflix and discovering a Singaporean Youtuber based in Chicago. I’ve always believed that anyone can be successful through…

Why Protein Is Crucial For Your Fat Loss Goals

This is one of the few things that pretty much everyone agrees with when it comes to optimizing weight loss. In fact, I don’t think I’ve ever heard someone say “you should lower your protein intake…