Chinaunix

标题: makefile问题请教 [打印本页]

作者: xuzmsa    时间: 2011-07-31 12:28
标题: makefile问题请教
写了一个程序rand_array, 目录结构如下:

rand_array/:
build  includes  libs  srcs

rand_array/build:
Makefile

rand_array/includes:
bitmap.h  rand_int.h  rand_order.h

rand_array/srcs:
rand_array.c  rand_int.c  rand_order.c




现在在rand_array/build目录下执行make命令总是报错,
提示找不到头文件, 错误信息:

set -e; rm -f ../srcs/rand_order.d; \
        gcc -MM  ../srcs/rand_order.c > ../srcs/rand_order.d.$$; \
        sed 's,\(../srcs/rand_order\)\.o[ :]*,\1.o ../srcs/rand_order.d:,g' < ../srcs/rand_order.d.$$ > ../srcs/rand_order.d;\
        rm -f ../srcs/rand_order.d.$$;
../srcs/rand_order.c:5:20: error: bitmap.h: No such file or directory
../srcs/rand_order.c:6:22: error: rand_int.h: No such file or directory
../srcs/rand_order.c:7:24: error: rand_order.h: No such file or directory
set -e; rm -f ../srcs/rand_int.d; \
        gcc -MM  ../srcs/rand_int.c > ../srcs/rand_int.d.$$; \
        sed 's,\(../srcs/rand_int\)\.o[ :]*,\1.o ../srcs/rand_int.d:,g' < ../srcs/rand_int.d.$$ > ../srcs/rand_int.d;\
        rm -f ../srcs/rand_int.d.$$;
../srcs/rand_int.c:5:22: error: rand_int.h: No such file or directory
set -e; rm -f ../srcs/rand_array.d; \
        gcc -MM  ../srcs/rand_array.c > ../srcs/rand_array.d.$$; \
        sed 's,\(../srcs/rand_array\)\.o[ :]*,\1.o ../srcs/rand_array.d:,g' < ../srcs/rand_array.d.$$ > ../srcs/rand_array.d;\
        rm -f ../srcs/rand_array.d.$$;
../srcs/rand_array.c:6:22: error: rand_int.h: No such file or directory
../srcs/rand_array.c:7:24: error: rand_order.h: No such file or directory
gcc -Wall -g   -c -o ../srcs/rand_array.o ../srcs/rand_array.c
../srcs/rand_array.c:6:22: error: rand_int.h: No such file or directory
../srcs/rand_array.c:7:24: error: rand_order.h: No such file or directory
../srcs/rand_array.c: In function ‘main’:
../srcs/rand_array.c:45: warning: implicit declaration of function ‘rand_order1’
../srcs/rand_array.c:48: warning: implicit declaration of function ‘rand_order2’
../srcs/rand_array.c:51: warning: implicit declaration of function ‘rand_order3’
make: *** [../srcs/rand_array.o] Error 1



makefile内容如下:

LIB_DIR:=../lib/
SRC_DIR:=../srcs/
INC_DIR:=../include/

GPATH=$(LIB_DIR)(SRC_DIR)

EXEC=rand_array
SRCS:=$(addprefix $(SRC_DIR),$(filter %.c,$(shell ls $(SRC_DIR))))
OBJS:=$(patsubst %.c,%.o,$(SRCS))
DEPS:=$(SRCS:.c=.d)
#MISSING_DEPS:=$(filter-out $(shell find $(SRC_DIR) *.d),$(DEPS))

CFLAGS:=-Wall -g
CC:=gcc

sinclude $(DEPS)

$(EXEC): $(OBJS)

%.d: CFLAGS:=-MM
%.d: %.c
        set -e; $(RM) $@; \
        $(CC) $(CFLAGS) $(CPPFLAGS) $< > $@.$$$$; \
        sed 's,\($*\)\.o[ :]*,\1.o $@:,g' < $@.$$$$ > $@;\
        $(RM) $@.$$$$;

刚开始学习Makefile,不知道Makefile哪里出问题了,
求指点,非常感谢!
作者: taojie2000    时间: 2011-07-31 12:35
回复 1# xuzmsa


    rand_order.c:5:20: error: bitmap.h: No such file or directory     这些.h 都没找到   不太懂   你最好查查 为什么没找到
作者: xuzmsa    时间: 2011-07-31 12:49
回复 2# taojie2000


在.c文件中都include对应的.h文件了,格式如下:

#include “bitmap.h”
#include  ...
...

在makefile中加了一条规则
%.o: %.c
         $(COMPLILE.c) $< -I$(INC_DIR) $(OUTPUT_OPTION)

还是不行




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2