I have been trying to make a correct makefile for a while now but I keep getting the error
"make: *** No rule to make target `all'. Stop."
I have one main program: mpasswdsort.c and the c file which is used by mpasswdsort, it comes with a header as well: list.c and list.h
my makefile:
CC=gcc
CFLAGS=-Wall -pedantic -ansi
all: mpasswdsort
server: mpasswdsort.o list.o
$(CC) mpasswdsort.o list.o -o mpasswdsort
mpasswdsort.o: mpasswdsort.cpp
$(CC) $(CFLAGS) mpasswdsort.cpp
list.o: list.cpp
$(CC) $(CFLAGS) list.cpp
clean:
rm -f server client *.o core
I am unsure if it's wrong in the makefile or if the makefile isn't supposed to be a .txt file.
all
comprisesmpasswdsort
but you have no rule formpasswdsort
– Bookkeepermake
can figure out a way to buildmpasswdsort
via one of its built-in rules then it is not necessary to provide an explicit one. In this case, it would try to build it frommpasswdsort.o
, which it does have an explicit rule for building. I guess that would probably fail to link, but the diagnostics would be much different than those presented in the question. – Litchmake
has some built-in knowledge, and doesn't need you to tell it everything. In fact, you can use it completely without a makefile if the default rules suffice, and sometimes I do so. – Litchmake server
(and the makefile problem for theall
target is fixed), then thempasswdsort
program will be relinked from the two object files each time you runmake server
, because the rules for theserver
target do not create a file calledserver
. And if you runmake mpasswdsort
, thenmake
will try to build the program from a single file —mpasswdsort.o
built frommpasswdsort.cpp
— and presumably fail becauselist.o
is not included. You'll need to sort that out eventually (becausemake all
will try to buildmpasswdsort
using a single file). – Vital