简体   繁体   中英

Makefile Produces Errors but Builds Fine?

I'm using a makefile to build several programs. Here's the code:

SRCS = prog1.c prog2.c prog3.c
TARG = all
CC = gcc
OPTS = -O
LIBS = -lm

OBJS = $(SRCS:.c=.o)

all: $(TARG)

$(TARG): $(OBJS)
    $(CC) -o $(TARG) $(OBJS) $(LIBS)

%.o: %.c
    $(CC) $(OPTS) -c $< -o $@

clean:
    rm -f $(OBJS) $(TARG)

This makefile perfectly generates three prog.o files, but I'm getting one error that is confusing me:

Makefile:12: recipe for target 'all' failed

I've done a fair amount of searching and can't find anything relating to my particular problem, so I was wondering if anyone had some insight into what is going on here. Thanks a bunch!

With TARG = all , you have:

all: all

all: $(OBJS)

Name your program something else, not all .

You have cyclic dependency of all depending on all (because TARG expands to all ). The dependency graph must be a DAG. change

TARG = all

to

TARG = something

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM