30
votes

I keep getting this error:

make: *** No rule to make target `all'.  Stop.

Even though my make file looks like this:

CC=gcc
CFLAGS=-c -Wall

all: build

build: inputText.o outputText.o main.o
    gcc main.o inputText.o outputText.o -o main

main.o: main.c
    $(CC) $(CFLAGS) main.c -o main.o

inputText.o: inputText.c
    $(CC) $(CFLAGS) inputText.c -o inputText.o

outputText.o: outputText.c
    $(CC) $(CFLAGS) outputText.c -o outputText.o

Yes there should be a tab space underneath the target and there is in my make file.

I can get it to work if I try one of the targets like main.o, inputText.o and outputText.o but can't with either build or all.

EDIT: I just randomly tried running make and telling it the file using the following command:

make -f make

This works but why doesn't just typing make work?

1
Can't repro with what you have here. Make sure you don't have funny characters in your file (copy paste what you have here and replace spaces with tabs).Mat
Your makefile should be named makefile, not make.Paul R
@PaulR Ahh that fixed it. It wasn't very well explained in my notes that it had to be called makefile.Dean
You can call it anything you like, but as you found, you then need the -f option with make. Using the default name of makefile just makes life easier. I'll make the above comment an answer for any future travellers along this road.Paul R

1 Answers

27
votes

Your makefile should ideally be named makefile, not make. Note that you can call your makefile anything you like, but as you found, you then need the -f option with make to specify the name of the makefile. Using the default name of makefile just makes life easier.