user1421147
user1421147

Reputation: 17

In MAKE file : error showing no such file or directory

I have simple Makefile. When I run make I get following error:

gcc  -I -o server server.o comfunc.o

gcc: error: comfunc.o: No such file or directory

make: *** [server] Error 1

My Makefile:

 CC=gcc

 CFLAGS=-I

AIM = server

HEADS = ../common/common.h

OBJS = comfunc.o

MOBJ = server.o

MISCS = server.cfg

SRCS = ${OBJS:.o=.c} ${MOBJ:.o=.c}

#targets
all: $(AIM)


server:server.o

        $(CC) $(LDFLAGS) $(CFLAGS) -o server server.o $(OBJS) $(LIBS)

#dependency
$(OBJS):../common/common.h

comfunc.o: ../common/common.h

#--End of Makefile--

Upvotes: 0

Views: 724

Answers (1)

Sagar Sakre
Sagar Sakre

Reputation: 2426

Add $(OBJS) and $(MOBJ) as dependency for server which will make sure the implicit Makefile rules are executed which produces corresponding .os

Refer the Makefile below

CC=gcc

 CFLAGS=-I

AIM = server

HEADS = ../common/common.h

OBJS = comfunc.o

MOBJ = server.o

MISCS = server.cfg

SRCS = ${OBJS:.o=.c} ${MOBJ:.o=.c}

#targets
all: $(AIM)


server:server.o $(OBJS) $(MOBJ)

        $(CC) $(LDFLAGS) $(CFLAGS) -o server server.o $(OBJS) $(LIBS)

#dependency
$(OBJS):../common/common.h

comfunc.o: ../common/common.h

Upvotes: 1

Related Questions