-2

I am trying to create a new C program, but I can't get the program to compile. This is because my makefile seems to be wrong. I keep getting "No rule to make target 'all'" and "No rule to make target 'clean'". Here is what I have so far:

Main program:

#include <stdio.h>

Sleepy() {

main (); {
    printf("Hello world");
}

}

Header (Although I haven't done anything to it yet):

#ifndef SLEEPY_H_
#define SLEEPY_H_



#endif /* SLEEPY_H_ */

And the Makefile:

CC = gcc
CFLAGS = -c

Sleepy.o: Sleepy.c Sleepy.h
$(CC) $(CFLAGS) Sleepy.c

Sleepy: Sleepy.o
$(CC) -o Sleepy.exe Sleepy.o


all: Sleepy

clean:
rm -rf *.0 a.out

make = all

I've been reading all kinds of tutorials, but I can't seem to get it to work. Would someone help me with this?

4

2 回答 2

1

To achieve your compilation, following changes are required.

Sleepy.c

#include <stdio.h>

int main (void) {
    printf("Hello world");
}

Makefile

CC = gcc
CFLAGS = -c

all: Sleepy

Sleepy.o: Sleepy.c Sleepy.h
    $(CC) $(CFLAGS) Sleepy.c

Sleepy.exe: Sleepy.o
    $(CC) -o Sleepy.exe Sleepy.o

clean:
    rm -rf *.o Sleepy.exe

Please note the change in clean rule of your Makefile. You will have to remove the executable which is Sleepy.exe

NOTE: The rules for Sleepy.o and Sleepy should be offset by a TAB and not space. Else, you will run into this error: makefile:5: *** missing separator. Stop

于 2013-03-24T01:25:15.347 回答
0

try this one,

All: sleepy

sleepy: sleepy.c sleepy.o sleepy.h 
        gcc sleepy.c -o sleepy
clean:
        rm -f *.o
于 2013-03-24T01:26:31.070 回答