Reputation: 17
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
Reputation: 2426
Add $(OBJS) and $(MOBJ) as dependency for server which will make sure the implicit Makefile rules are executed which produces corresponding .o
s
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