简体   繁体   中英

Makefile produces error “No rule to make target”

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

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 .

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM