2
votes

I've tried to fix this using the other two most relevant topics: Makefile error: No rule to make target Makefile: No rule to make target. Stop

But neither seem to solve my issue.

I'm unsure where my code went wrong, as my instructor verified that the code works on his end.

The code for my makefile is:

TARGET  = demo
FILES   = test.c
OBJS    = $(FILES:.c=.o)
ASMS    = $(FILES:.c=.s)

all:    $(TARGET)

$(TARGET):  $(OBJS)
    gcc -o $@ $^

%.o:    %.c
    gcc -c $< -o $@

%.s:    %.c
    gcc -S -masm=intel $< -o $@

asm:    $(ASMS)

run:    $(TARGET)
    ./$(TARGET)

clean:
    rm -f $(TARGET) $(OBJS) $(ASMS)

However, when I attempt to do "make run" it produces the result

make: *** No rule to make target 'run'. Stop.

As seen here image

The actual code to my program that I'm trying to compile is only 4 lines long. I don't think it's the reason for the issue

#include <stdio.h>
char *msg = "Exam Lab 1";

int main(int argc, char *argv[]) {
    printf("%s\n", msg);
}

Here's the contents of the directory I'm running make from:

http://i.imgur.com/r5EnwHj.png

2
Make sure the indented lines for each recipe are using only tab characters, not spaces.dbush
Thank you for the reminder. Completely forgot that makefiles rely on tabs, however I'm running into the problem still. i.imgur.com/wioJc37.pngCashews
What are the contents of the directory you're running make from? The makefile (named either Makefile or makefile) and the .c files should be there.dbush
Also, are you using GNU make? (run make -v to find out).dbush
Yeah, all the files are in the same directory, and I'm using GNU Make 4.1. i.imgur.com/r5EnwHj.pngCashews

2 Answers

2
votes

Your makefile doesn't have the correct name.

By default, make looks for a file named either makefile or Makefile. Yours is named Makefile.txt, so make can't find it.

Either change the name to makefile or Makefile, or use the -f option to specify the makefile name, ex. make -f Makefile.txt.

2
votes

From the image you've provided it's clear that you've named the file Makefile.txt. As @dbush says, the makefile MUST be named either Makefile or makefile. Those are the only file names make looks for by default.

Either that or you have to run make -f Makefile.txt.