S开发者_如何学运维OURCES = server.c
TARGET = Server
CC = gcc
all: $(SOURCES) $(TARGET)
$(CC) $(SOURCES) -o $(TARGET)
clean:
rm -rf $(TARGET)
Above is the Makefile of my web server. Though server.c file is in the directory this gives the fallowing error
make: *** No rule to make target `Server', needed by `all'. Stop.
What is the mistake I've made and how to solve it.
I think your makefile got garbled somewhere between your machine and the post, but there is a simple fix that I think will work:
all: $(SOURCES)
That will (probably) solve the problem and make the error go away-- if that's all you want then you can stop reading. But there are still things wrong with this makefile, so we can make some more improvements.
First, a little adjustment to make it match what I think your makefile really says:
SOURCES = server.c
TARGET = Server
CC = gcc
all: $(SOURCES) $(TARGET)
$(CC) $(SOURCES) -o $(TARGET)
clean:
rm -rf $(TARGET)
The first three lines and the clean
rule are all right, we'll ignore those. Now we give TARGET
its own rule and straighten out the prerequisites:
all: $(TARGET)
$(TARGET): $(SOURCES)
$(CC) $(SOURCES) -o $(TARGET)
Now we make all
PHONY (since it doesn't really make a file called "all"), and introduce automatic variables to make the TARGET
rule more robust and less redundant:
.PHONY: all
all: $(TARGET)
$(TARGET): $(SOURCES)
$(CC) $< -o $@
There's more to learn if your codebase gets more complicated, but that'll do for now.
just do "make clean" to clean all links, then run make again. Everything should be good.
My issues was I had the name and the command on the same line. Make: sure you are using tabs and not spaces. (no pun intended)
BEFORE (Broken)
build: docker build...
AFTER
build:
docker build...
精彩评论