免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2204 | 回复: 2
打印 上一主题 下一主题

makefile问题请教 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-07-31 12:28 |只看该作者 |倒序浏览
写了一个程序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哪里出问题了,
求指点,非常感谢!

论坛徽章:
0
2 [报告]
发表于 2011-07-31 12:35 |只看该作者
回复 1# xuzmsa


    rand_order.c:5:20: error: bitmap.h: No such file or directory     这些.h 都没找到   不太懂   你最好查查 为什么没找到

论坛徽章:
0
3 [报告]
发表于 2011-07-31 12:49 |只看该作者
回复 2# taojie2000


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

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

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

还是不行
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP