编辑源文件后,"make"不会重新编译

编程入门 行业动态 更新时间:2024-10-22 10:35:59
本文介绍了编辑源文件后,"make"不会重新编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在用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"不会重新编译

本文发布于:2023-11-07 11:09:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566289.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:源文件   编辑   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!