1: Four Phases of GCC compilation: preprocessing, compiling, compiling, linking
#vi file.c
#gcc-E file.c-o file.i//-e view and stop compiling after preprocessing,-o to generate the target file,- i means preprocessed
#gcc-S File.i-o file.s//-s compiled to assembly without assembly and linking
#gcc-C file.s-o file.o//-c compile to target code
#gcc file.o-o file//-o file output to a file
# gcc-static File.c-o file//-static Disable the use of dynamic libraries
; Makefile Basic Rules
1 All:test
2 echo "Hello World"
3 Test:
4 @echo "Hi Hi"
; with Tab Key Space
;all,test is the target
; 2,4 is the command that generates the target
#make ( default run 1), &make all, &make test
; Makefile Dependency Relationship
1 SIMPLE:MAIN.O foo.o BAR.O
2 gcc-o Simple MAIN.O foo.o bar.o// execute command
3 MAIN.O:MAIN.C
4 gcc-c main.c-o main.o// generate command
5 FOO.O:FOO.C
6 Gcc-c Foo.c-o FOO.O
7 BAR.O:BAR.C
8 Gcc-c Bar.c-o BAR.O
9 Clean:
RM *.o// clearly generated files
; Simple depends on:main.o foo.o BAR.O
Three . o files are also dependent on three . C files
#touch foo.c bar.c// do not write the main function, many times to define the error
#vi main.c// Write the main function
#make clean// execution
; false target: . Phony
1. Phony:clean
2 Test:
3 echo "Hello"
4 Clean:
5 RM *.c
; when the directory has other Clean you can use false targets when you are not associated with a file
; #vi test.c
#gcc-C test.c
# ls
TEST.c TEST.O ( target file )
#gcc-o Test ( executable file ) TEST.O
# ls
Test test.c TEST.O
; One main program calls another subroutine
# Cat TEST.c test2.c
#include <stdio.h>
int main ()
{printf (" Hello, I have the Lord \ \");
Test_2 ();
return 0;}
------------------------------------------
void test_2 (void)
{printf (" Thank you, you are also good!") \ n ");
return 0;}
# gcc-c TEST.c test2.c
test2.c test2.o test.c TEST.O
# Gcc-o Test TEST.O TEST2.O
Test test2.c test2.o test.c TEST.O
Four phases of GCC compilation: preprocessing, compiling, compiling, linking