include/a.h
#define PI 3.14
void f1();
include/b.h
void f2();
src/a.c
#include <stdio.h>
#include "a.h"
void f1() {
printf("A f1\n");
printf("Pai = %f \n", PI);
printf("\n");
}
src/b.c
#include <stdio.h>
#include "b.h"
void f2() {
printf("B f2\n");
}
src/m.c
#include <stdio.h>
#include "a.h"
#include "b.h"
int main() {
f1();
f2();
return 0;
}
INC = -I./include
SRC = ./src
main: a.o b.o $(SRC)/m.c
cc $(INC) -o main $(SRC)/m.c a.o b.o
a.o: $(SRC)/a.c
cc $(INC) -c $(SRC)/a.c
b.o: $(SRC)/b.c
cc $(INC) -c $(SRC)/b.c
.PHONY: clean run
clean:
rm -rf *.o main
run: main
./main
运行
make run
来源:oschina
链接:https://my.oschina.net/u/3845788/blog/3010050