(Test version: RedHat9.0 Simplified Chinese version) first create the following instance program text: /************************** filename: main. c **************************/# include & lt; stdio. h & gt; # include & lt; stdlib. h & gt; # include "hello. h "# include" init. h"
(Test version: RedHat 9.0 Simplified Chinese Version)
First, create the following instance program text:
/************************** Filename: main. c **************************/
# Include
# Include
# Include "hello. h"
# Include "init. h"
Void aftermain (void)
{
Printf ("\ n ");
Printf ("<>>>>>>>>> \ n ");
Printf ("... \ n ");
Return 0;
}
Int main (int argc, char * argv [])
{
Printf ("========= main =========\ n ");
Init (1, 1234 );
Hello (argc, argv );
Atexit (aftermain );
Printf ("... exit main... \ n ");
Return 0;
}
/********************** Filename: init. c ***************************/
# Include
# Include "init. h"
Const char ro_data [1024] = {"This is readonly data "};
Static char rw_data [1024] = {"This is readwrite data "};
Static char bss_data [1024];
Int init (int number)
{
Printf ("input number: % d \ n", number );
Printf ("ro_data: % x, % s \ n", (unsigned int) ro_data, ro_data );
Printf ("rw_data: % x, % s \ n", (unsigned int) rw_data, rw_data );
Printf ("bss_data: % x, % s \ n", (unsigned int) bss_data, bss_data );
Return number;
}
/******************* Filename: hello. c ********************/
# Include
# Include "hello. h"
Int hello (int argc, char * argv [])
{
Int I;
Printf ("Hello world! \ N ");
For (I = 0; I
{
Printf ("argv [% d] = % s \ n", I, argv [I]);
}
Return 0;
}
/**************** Filename: init. h *************************/
# Ifndef _ INIT_H _
# Define _ INIT_H _
Int init (int number );
# Endif
/********************* Filename: hello. c *********************/
# Ifndef _ HELLO_H _
# Define _ HELLO_H _
Int hello (int argv, char * argc []);
# Endif
You can see from the dependency:
All: main. o hello. o init. o
Main. o: main. c hello. h init. h
Hello. o: hello. c hello. h
Init. o init. h init. c
Create a terminal and enter
Vi makefile1
Create a makefile1 text file
All: main. o hello. o init. o
Gcc-o myapp main. o hello. o init. o
Main. o: main. c hello. h init. h
Gcc-c main. c
Hello. o: hello. c hello. h
Gcc-c hello. c
Init. o: init. c init. h
Gcc-c init. c
Note: ":" is followed by a tab rather than a space.
Input make-f makefile on the terminal to complete the compilation.
Note in Make file starts #