当前位置: 技术问答>linux和unix
Makefile的编写问题?
来源: 互联网 发布时间:2016-08-11
本文导语: 我正在学习make,目录组织结构如下: inc/hello.h src/hello.c main.c Makefile 我在make的时候总是说找不到hello.c 我的Makefile如下: # String declaration objects = main.o hello.o # Command app : $(objects) cc -o app $(objects) main.o : main.c...
我正在学习make,目录组织结构如下:
inc/hello.h
src/hello.c
main.c
Makefile
我在make的时候总是说找不到hello.c
我的Makefile如下:
不知道为什么.h的路径好像可以,.c的路径就不可以
请高手指点!
inc/hello.h
src/hello.c
main.c
Makefile
我在make的时候总是说找不到hello.c
我的Makefile如下:
# String declaration
objects = main.o hello.o
# Command
app : $(objects)
cc -o app $(objects)
main.o : main.c hello.h stdio.h
cc -c main.c
hello.o : hello.c stdio.h
cc -c hello.c
# Search paths
vpath %.h /usr/include/
vpath %.h ./inc/
vpath %.c ./src/
# Clean the intermediate files
.PHONY : clean
clean :
rm app *~ $(objects)
不知道为什么.h的路径好像可以,.c的路径就不可以
请高手指点!
|
vpath只是对Makefile指定搜索路径,不是为gcc执行搜索路径 还要有-I
http://blog.csdn.net/weihua1984/archive/2010/01/06/5142491.aspx
我这里说的很清楚了
http://blog.csdn.net/weihua1984/archive/2010/01/06/5142491.aspx
我这里说的很清楚了
|
系统自己能处理的东西就不要多事。
# String declaration
CFLAGS = -I. -I./inc
objects = main.o hello.o
# Command
app : $(objects)
$(CC) -o $@ $(objects)
main.o: hello.h
hello.o: hello.h
# Search paths
vpath %.h inc
vpath %.c src
# Clean the intermediate files
.PHONY : clean
clean :
rm -f app *~ $(objects)