makefile - make: *** No rule to make target all'. Stop
Asked Answered
S

5

10

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.

Scission answered 8/9, 2017 at 18:16 Comment(7)
As @JohnBollinger said - what is the name of your makefile (and what are it's permissions)?Bookkeeper
Also, your makefile says all comprises mpasswdsort but you have no rule for mpasswdsortBookkeeper
And that is likely an error, @KevinDTimm, but not necessarily one. If make can figure out a way to build mpasswdsort 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 from mpasswdsort.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.Litch
@JohnBollinger - I point it out so that the OP writes a correct, explicit makefile instead of what is currently here. Specifically becuause, when the next newbie comes along to troubleshoot this, they will be lost. Finally, given the diagnostics, I doubt that this is the actual makefile being used.Bookkeeper
And I'm not criticizing, @KevinDTimm; I'm simply clarifying for that next newbie that make 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.Litch
If you say make server (and the makefile problem for the all target is fixed), then the mpasswdsort program will be relinked from the two object files each time you run make server, because the rules for the server target do not create a file called server. And if you run make mpasswdsort, then make will try to build the program from a single file — mpasswdsort.o built from mpasswdsort.cpp — and presumably fail because list.o is not included. You'll need to sort that out eventually (because make all will try to build mpasswdsort using a single file).Vital
I didn't see criticism @JohnBollinger - I saw teaching. At this point I would just like the OP to be interested in their posted question......Bookkeeper
L
13

The error message you present indicates that make does not see any rule for building target "all". It is exactly the same diagnostic that GNU make emits when there is no makefile at all. Since the makefile contents you present do contain a rule for target "all", I conclude that make is not seeing them.

That may be because the makefile is in a different directory, because its name is different from the ones make tries by default (Makefile or makefile is conventional; GNU's version of make also checks for GNUmakefile), or because an access-control issue prevents make from reading the file. Since you remark

I am unsure if its wrong in the makefile or if the makefil isnt supposed to be a .txt file.

, the most likely conclusion is that (at least) the filename is wrong. Makefiles are text files, but text file names don't necessarily end with ".txt". In fact, on Linux and other UNIXes, most of them don't. Makefiles shouldn't have such an extension, though, technically, you can use the -f option to tell make the name of the makefile to use.

Litch answered 8/9, 2017 at 18:29 Comment(2)
All standard versions of make look for both makefile and Makefile (in that order) based on the behaviour of the original Unix make program — see POSIX make. On a case-insensitive file system (Mac, Windows), there isn't a difference between those, of course.Vital
Thanks, @JonathanLeffler, I have updated the answer in light of your comment.Litch
T
3

I'm using a MAC so renaming the "MakeFile" to "Makefile" did the trick for me.

And one more thing, I got this error after fixing the previous one:

Makefile:3: *** missing separator. Stop.

Replacing the four spaces with tabs solved this problem for me! Simply just delete the space before the commands in your "Makefile" and put a tab behind them.

Taxexempt answered 7/2, 2023 at 11:0 Comment(0)
K
0

For me, quite simply, I was initiating the make init command outside of the target directory that I wished to create the makefile. Hope this helps someone.

Kaine answered 14/7, 2022 at 21:20 Comment(0)
P
0

For me, I had a folder called "project1_src" that contained the project files as well as the makefile, inside of another folder with the same name ("project1_src"). Once I got the folder that actually contains files out and deleted the parent folder, the makefile works normally.

Pigpen answered 6/7, 2023 at 14:54 Comment(0)
A
0

In my situation, Makefile can not be recognized, but makefile can, and the error is can not find makefile actually.

Apocarp answered 31/5, 2024 at 12:16 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.