We are writingProgramIn this case, some methods will be encapsulated for reuse, which involves compilation of multiple files, how to compile these different files, link them to the final executable program, and how to manage these files, one compilation?
Compile the math. h header file
/* -- ===-------------------------------------------- = ---
Filename: Math. h
Simple File Operations
-- ===-------------------------------------------- = --- */
Extern Int Add ( Int I, Int J );
Compile the math. c file
/* -- ===-------------------------------------------- = ---
Filename: Math. c
Implement the methods defined in the math. h file
Compilation Method: gcc-C math. C-o math. o
-- ===-------------------------------------------- = --- */
Int Add ( Int I, Int J)
{
Return I + J;
}
Compile main. C program
/* -- ===-------------------------------------------- = ---
Filename: Main. c
Main Program, test the math. h and math. c files.
Compilation Method: gcc-C main. C-o main. o
-- ===-------------------------------------------- = --- */
# Include " Math. h "
# Include < Stdio. h >
Int Main ( Int Argc, Int Argv)
{
Printf ( " The sum 3 + 5 = % d. \ n " , Add ( 3 , 5 ));
Return 0 ;
}
FinallyGCC main. O math. O-o mainGenerate the main program.
Xumh @ Ubuntu :~ /CPP/make $ cat makefile
Main: Main. O math. o
GCC main. O math. O-o main
Main. O: Main. C math. h
Gcc-C main. C-o main. o
Math. O: Math. C math. h
Gcc-C math. C-o math. o
Clean:
Rm-f *. o
Xumh @ Ubuntu :~ /CPP/make $