Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

c - gcc: "No such file or directory"

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

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

1 Reply

0 votes
by (71.8m points)
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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...