makefile不更改输入文件名

发布于 2025-01-24 15:17:35 字数 736 浏览 3 评论 0原文

我正在尝试制作一个C程序并具有以下makefile:

CC=clang
CFLAGS=-std=c99 -Wall -pedantic
LDFLAGS=
LDLIBS=
OUT=nes_slop
SRC_DIR=src/
OBJ_DIR=obj/
SRCS=$(wildcard $(SRC_DIR)*.c)
OBJS=$(addprefix $(OBJ_DIR),$(notdir $(SRCS:.c=.o)))
MAKE=make
CLEAR=TRUE

all: clean $(OUT)

clean:
    rm -i $(OUT) $(OBJS) -f

$(OUT): $(OBJS)
    $(CC) $(CFLAGS) $(OBJS) -o $(OUT)

$(OBJS): $(SRCS)
    $(CC) -c $(CFLAGS) $(LDLIBS) $< -o $@

一切都很好,直到我拥有超过1个.c文件:

clang -c -std=c99 -Wall -pedantic -lncurses  src/gamestate.c -o obj/gamestate.o
clang -c -std=c99 -Wall -pedantic -lncurses  src/gamestate.c -o obj/main.o

因此,某种程度上没有更新源文件,它始终是gamestate.c < /code> ...我的makefile怎么了?感谢任何帮助,谢谢

I am trying to make a C program and have the following makefile:

CC=clang
CFLAGS=-std=c99 -Wall -pedantic
LDFLAGS=
LDLIBS=
OUT=nes_slop
SRC_DIR=src/
OBJ_DIR=obj/
SRCS=$(wildcard $(SRC_DIR)*.c)
OBJS=$(addprefix $(OBJ_DIR),$(notdir $(SRCS:.c=.o)))
MAKE=make
CLEAR=TRUE

all: clean $(OUT)

clean:
    rm -i $(OUT) $(OBJS) -f

$(OUT): $(OBJS)
    $(CC) $(CFLAGS) $(OBJS) -o $(OUT)

$(OBJS): $(SRCS)
    $(CC) -c $(CFLAGS) $(LDLIBS) 
lt; -o $@

It was all well and good until I had more than 1 .c file:

clang -c -std=c99 -Wall -pedantic -lncurses  src/gamestate.c -o obj/gamestate.o
clang -c -std=c99 -Wall -pedantic -lncurses  src/gamestate.c -o obj/main.o

so, somehow the source file is not being updated, it's always gamestate.c... what's wrong with my makefile? any help is appreciated, thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱的十字路口 2025-01-31 15:17:35

简而言之,您的规则应该看起来像这样:

$(OBJS): %.o: %.c
    $(CC) -c $(CFLAGS) $(LDLIBS) 
lt; -o $@

您可能还需要阅读 this 有关如何生成自动依赖关系(因此,如果更改标头文件,则C文件将根据需要自动重新生成),如果您不感兴趣,则该页面上有一个TL; DR部分在细节中。

In short, your rule should look something like this:

$(OBJS): %.o: %.c
    $(CC) -c $(CFLAGS) $(LDLIBS) 
lt; -o $@

You may also want to read this for how to generate automatic dependencies (so if you change a header file, your c files will automatically regenerate as needed) There's a TL;DR section at the top of that page, if you're not interested in the details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文