编辑源文件后,"make"不会重新编译 [英] 'make' does not recompile when source file has been edited
问题描述
我正在用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 10
The 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.h
Alternatively, modify your existing rule to be:
%.o : %.c functions.h
$(CC) -c $< -o $@
这篇关于编辑源文件后,"make"不会重新编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!