在一个文件夹下一共四个文件
function.h
#ifndef __FUNCTION_H__
#define __FUNCTION_H__
void func();
#endif
function.c
#include<stdio.h>
#include "function.h"
void func()
{
printf("this is function.c");
}
test.c
#include <stdio.h>
#include "function.h"
void main() {
func();
printf("Hello world!\n");
}
Makefile
default: function.o test.o
cc -o test function.o test.o
#tab 开头
function.o: function.c function.h
cc -c function.c
test.o: test.c function.h
cc -c test.c
执行make操作
root@ubuntu:/var/test# make
cc -c function.c
cc -c test.c
cc -o test function.o test.o
root@ubuntu:/var/test# ll
total 40
drwxr-xr-x 2 root root 4096 Apr 7 17:33 ./
drwxr-xr-x 15 root root 4096 Mar 24 17:44 ../
-rw-r--r-- 1 root root 91 Mar 24 17:44 function.c
-rw-r--r-- 1 root root 67 Mar 24 17:44 function.h
-rw-r--r-- 1 root root 1024 Apr 7 17:33 function.o
-rw-r--r-- 1 root root 161 Mar 24 17:52 Makefile
-rwxr-xr-x 1 root root 7377 Apr 7 17:33 test*
-rw-r--r-- 1 root root 100 Mar 24 17:44 test.c
-rw-r--r-- 1 root root 1052 Apr 7 17:33 test.o
root@ubuntu:/var/test# ./test
this is function.cHello world!