Home > Blockchain >  An introduction to the underlying
An introduction to the underlying

Time:09-24

Learning the basic concept of GCC and simple usage,
1, GCC and GCC

GCC (GNU Compiler Collection)

The GNU compiler collection, including many language compiler, including C, C + +, Java, etc.
GCC for compilation of the embedded operating system, such as Linux, VxWorks, Android, etc.
GCC single refers to the C language in the GCC compiler

GCC for kernel development and a few more application development
2, working behind the scenes of GCC

Would like to know more detail about compiling link deep content, please read the books with "CSAPP" chapter 7 "programmer self-improvement", because here I record only the results of learning and the commonly used several compilation method,

Let's look at a simple program:

Test. C source program:

# include & lt; stdio.h>
# include "func. H"

Int g_global=0;
Int g_test=1;

Int main (int arg c, char * argv [])
{
Func ();

Printf (" & amp; G_global=% p \ n ", & amp; G_global);
Printf (" & amp; G_test=% p \ n ", & amp; G_test);
Printf (" & amp; Func %=p \ n ", & amp; Func);
Printf (" & amp; The main p=% \ n ", & amp; The main);

return 0;
}

1
2
3
4
5
6
7
8
9
10
11.
12
13
14
15
16
17
18
Func. H header file:

# include & lt; stdio.h>

Void func ()
{
# ifdef TEST
Printf (" TEST=% s \ n ", TEST);
# endif

return;
}
1
2
3
4
5
6
7
8
9
10
Under Linux using GCC to compile:

GCC test. C - o test
1
Then run:

./test
1
The results are as follows:

& G_global=0 x804a020
& G_test=0 x804a014
& Func=0 x80483c4
& The main=0 x80483c9
1
2
3
4
Obviously, the above procedure is very simple, freshmen all to know why, but today we are not learning the program, but want to know, run the GCC test. The c - o the test after the command, step by step is how to generate the executable test,

In fact, the C program to binary executable file from the source file, has the following four steps:

Pretreatment of CPP
C compiler cc
Assembly as
Link ld
Probably compile a source program for the process of binary files as shown in the figure below:
Insert picture description here

CodePudding user response:

QQ: 1247333786
  • Related