Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have received an error when i launched "make"

I didn't know where is the problem.

I guess in the makefile. Can you help me !Thanks :)

make: Circular src/amqp_consommateur.c <- obj/amqp_consommateur.o dependency dropped. make: Circular src/amqp_producteur.c <- obj/amqp_consommateur.o dependency dropped. make: Circular src/amqp_producteur.c <- obj/amqp_producteur.o dependency dropped. gcc obj/amqp_consommateur.o obj/amqp_producteur.o -o amqp_consommateur amqp_producteur -L. -lamqp gcc: error: obj/amqp_consommateur.o: No such file or directory gcc: error: obj/amqp_producteur.o: No such file or directory gcc: error: amqp_producteur: No such file or directory make: *** [src/amqp_producteur.c] Error 1

CC := gcc
CFLAGS := -Wall -Werror -g
SRCDIR := src
OBJDIR := obj
LDFLAGS :=
LIBS := -L. -lamqp
PROG := amqp_consommateur amqp_producteur
SRCS_RAW := amqp_consommateur.c amqp_producteur.c
#addprefix : src/amqp_consommateur obj/amqp_consommateur.o
SRCS := $(addprefix $(SRCDIR)/,$(SRCS_RAW))
OBJS := $(addprefix $(OBJDIR)/,$(SRCS_RAW:.c=.o))

.PHONY: all
all: $(OBJS)
    @echo "$(MAKE) : Tout est généré"

$(SRCS) : $(OBJS) 
    $(CC) $(OBJS) -o $(PROG) $(LIBS)
#rule to create object directory if it doesnt exist
$(OBJDIR):
    mkdir $(OBJDIR)
#define implicit rule to build objects in their own directory
#(note -- order only dependency on object directory)
$(OBJS): $(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
    $(CC) $(CFLAGS) -c $< 
.PHONY: clean
clean:
    $(RM) *~  $(EXEC)
    $(RM) -r $(OBJDIR)

enter image description here

question from:https://stackoverflow.com/questions/65915701/gcc-no-such-file-or-directory

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
288 views
Welcome To Ask or Share your Answers For Others

1 Answer

CC := gcc
CFLAGS := -Wall -Werror -g
LDFLAGS :=
LIBS := -L. -lamqp
SRCS := amqp_consommateur.c amqp_producteur.c

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

.PHONY: all
all: $(PROGS)
    @echo "$(MAKE) : Tout est généré"

$(PROGS) : % : %.o Makefile 
    $(CC) $< -o $@ 

%.o: %.c Makefile
    $(CC) $(CFLAGS) -c $< 

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...