In this paper, main.c and sum.c Example to Analyze how the compiler driver.
First the code.
main.c
1 /* main.c */ 2 /* $begin main */ 3 int sum(int *a, int n); 4 5 int array[2] = {1, 2}; 6 7 int main() 8 { 9 int val = sum(array, 2); 10 return val; 11 } 12 /* $end main */ 13 //wangtingyi
sum.c
/* sum.c */ /* $begin sum */ int sum(int *a, int n) { int i, s = 0; for (i = 0; i < n; i++) { s += a[i]; } return s; } /* $end sum */
In the shell to mobilize GCC driver by commands: gcc -Og -o prog main.c sum.c
(PS: Linux common commands, see end of text)
The following diagram overview of the driver sample program source code translation from ASCII files into the behavior of executable files.
The driver first run the C preprocessor cpp, it will be translated into C source code middleware an ASCII file of main.i;
cpp [other arguments] main.c /tmp/main.i
Next, Next, operation of the driver C compiler (CC1), it will be translated into an ASCII main.i member assembly language main.s;
CC1 /tmp/main.i -OG [OTHER arguments] -o / tmp / . main s
then, the driver runs the assembler (aS), it main.s translated into a relocatable object file (file rcatable obiject) main.o;
aS [OTHER arguments] -o /tmp/main.o / tmp / main. s
Driver through the same process generates sum.o. Finally, it runs the linker program ld, the combination main.o and sum.o as well as some necessary system object files together to create an executable object file (Executable Object File) PROG:
LD -o PROG [args System and Object Files ] /tmp/main.o / tmp / sum.o
to run an executable file prog, we lose people in the Linux shell command line its name:
shell call the operating system called loader (loader) function, which copy the executable code and data in the prog into memory, and then transfers control to the beginning of the program.
If the -v option to run with GCC will be as follows:
(Extended Information:
Linux commonly used commands:
1, cd: Change directory
usage: cd
cd ../ switch to the parent directory
cd / to switch to the root directory
cd ~ (or only cd) switch to the current user's home directory (home under the user name folder named ) / root directory
mkdir create a directory
mkdir -p directory name recursively create directories
2, rmdir to delete empty directories
usage: rmdir directory name
can also be used: rm -rf directory name
3, ls directory or file information view
main options:
the -l directory listing For more information or files. For example, permission, modification time and so on
-a list all files in the current directory, including hidden files (dot at the beginning are already hidden files))
The new one, but also look exhibitions!