1,问题描述
在 “include” 文件夹下编写简单头文件,如何被 “ lib ”文件夹的.c调用
1 #ifndef __1_H__ 2 #define __1_H__ 3 4 int num = 1; 5 6 7 8 9 #endif
2,问题解决
(1)主要命令 INCDIR := $(shell pwd)
(2)图示程序以及Makefile分布
(3)主要的思想:外层Make file调用“lib”文件夹下的Makefile
(4)外层Makefile
1 CC = gcc
2 INCDIR := $(shell pwd)
3 CPPFLAGS := -I$(INCDIR)/include
4 # C编译器的flag
5 CFLAGS := -Wall -O2 -fno-builtin
6 objs += lib/1
7 export CC CPPFLAGS CFLAGS
8
9 lib/1:
10 cd lib; make; cd ..
11
12 clean:
cd lib; make clean; cd ..
(5)“lib” 文件下的Makefile
1 objs=1.o
2
3 1:${objs}
4 ${CC} -o $@ $^
5
6 %.o:%.c
7 ${CC} $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
8 clean:
rm *.o 1 -f



