我正在用C写一些Conway的《生命游戏》的实现.源代码分为三个文件:main.c和functions.c/functions.h,在其中放置函数定义和声明.
现在,要创建一个单元格网格,我有一个这种类型的矩阵:
Cell grid[GRID_HEIGHT][GRID_WIDTH];其中GRID_HEIGHT和GRID_WIDTH是在functions.h中定义的常量:
#define GRID_HEIGHT 10 #define GRID_WIDTH 10程序运行正常,使用make和Makefile编译.但是问题是:如果我尝试更改GRID_HEIGHT或GRID_WIDTH,当我再次运行我的Makefile时,它说所有文件都是最新的! 我尝试使用良好的方法gcc main.c etc.进行编译,它可以正常运行.那么,为什么make不重新编译源代码?
这是我的Makefile:
CC = gcc OBJECTS = main.o functions.o Game\ of\ Life : $(OBJECTS) $(CC) $(OBJECTS) -o Game\ of\ Life -lncurses %.o : %.c $(CC) -c $<解决方案
因为您尚未告诉我们重新编译取决于functions.h.
尝试将其添加到您的Makefile中:
%.o : functions.h或者,将现有规则修改为:
%.o : %.c functions.h $(CC) -c $< -o $@I'm writing a little implementation of Conway's Game of Life in C. The source code is split in three files: main.c and functions.c/functions.h, where I put my functions definitions and declarations.
Now, to create a grid of cell, I have a matrix of this type:
Cell grid[GRID_HEIGHT][GRID_WIDTH];where GRID_HEIGHT and GRID_WIDTH are constants defined in functions.h:
#define GRID_HEIGHT 10 #define GRID_WIDTH 10The program runs fine, compiled with make and Makefile. But the problem is: if I try to change GRID_HEIGHT or GRID_WIDTH, when I run again my Makefile it says that all files are up-to-date! I've tried to compile using the good ol' way gcc main.c etc. and it runs as it should. So, why make does not recompile the source?
This is my Makefile:
CC = gcc OBJECTS = main.o functions.o Game\ of\ Life : $(OBJECTS) $(CC) $(OBJECTS) -o Game\ of\ Life -lncurses %.o : %.c $(CC) -c $<解决方案
Because you haven't told it that recompilation depends on functions.h.
Try adding this to your Makefile:
%.o : functions.hAlternatively, modify your existing rule to be:
%.o : %.c functions.h $(CC) -c $< -o $@
更多推荐
编辑源文件后,"make"不会重新编译
发布评论