Linux makefile experiment

Store the program according to the following directory structure, then make a makefile, and fill in the content of the makefile in the form.

An existing program consists of 5 files:

/* ./main.c */
#include "mytool1.h"
#include "mytool2.h"
intmain()
{
	mytool1_print("hello mytool1!\n");
	mytool2_print("hello mytool2!\n");
	return 0;
}
/* ./functions/mytool1.c */
#include "mytool1.h"
#include <stdio.h>
void mytool1_print(char *print_str)
{
	printf("This is mytool1 print : %s ",print_str);
}
/* ./functions/mytool1.h */
#ifndef _MYTOOL_1_H
#define _MYTOOL_1_H
	void mytool1_print(char *print_str);
#endif
/* ./functions/mytool2.c */
#include "mytool2.h"
#include <stdio.h>

void mytool2_print(char *print_str)
{
	printf("This is mytool2 print : %s ",print_str);
}
/* ./functions/mytool2.h */
#ifndef _MYTOOL_2_H
#define _MYTOOL_2_H
	void mytool2_print(char *print_str);
#endif
./Makefile
main:mytool1.o mytool2.o main.o
	gcc mytool1.o mytool2.o main.o -o main
main.o:main.c ./functions/mytool1.h ./functions/mytool2.h
	gcc -c main.c -o main.o -I functions
mytool1.o:./functions/mytool1.c ./functions/mytool1.h
	gcc -c ./functions/mytool1.c -o mytool1.o
mytool2.o:./functions/mytool2.c ./functions/mytool2.h
	gcc -c ./functions/mytool2.c -o mytool2.o
clean:
	rm -rf *.o main
Output result:








Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324886651&siteId=291194637