Reputation: 311
So here my code for a makefile :
CC=gcc
CFLAGS= -g -W -Wall -o
EXEC=program
all : $(EXEC)
program: apple.o cream.o cake.o program.o
$(CC) $(CFLAGS) program apple.o cream.o cake.o program.0
program.o: program.c apple.o cream.o cake.o
$(CC) $(CFLAGS) program.c
apple.o: apple.c apple.h
$(CC) $(CFLAGS) apple.c apple.h
cream.o: apple.o cream.c cream.h
$(CC) $(CFLAGS) cream.c cream.h
cake.o: cake.c cake.h cream.o apple.o
$(CC) $(CFLAGS) cake.c cake.h
clean:
-rm -rf *.o $(EXEC)
And im stuck with an error : *gcc: no input file make: *[program.o] Error 1***
Just to let you know.
I want to be able to create a makefile that will produce my exec 'program'. And i've read that i can use de -I flag which will look into the directory for the include header. But when i add the -I in my CFLAGS, it's getting worst
Thank you very much.
Upvotes: 0
Views: 2949
Reputation: 881323
CFLAGS= -g -W -Wall -o
:
program.o: program.c apple.o cream.o cake.o
$(CC) $(CFLAGS) program.c
The problem (one of them) lies there.
Since CFLAGS
ends with -o
, the specification for the output file, the command ends up being:
gcc -g -W -Wall -o program.c
In other words, you're specifying program.c
as the output file and providing no input file.
You need to specify the output file with something like:
program: program.c apple.o cream.o cake.o
$(CC) $(CFLAGS) program program.c apple.o cream.o cake.o
(though there are probably better ways to do this by using the meta-variables provided by make
).
You also seem to be under some confusion about the compilation process. Despite the fact your rule is for building the object file program.o
, the compiler options you have will try to generate a final executable (since they do not have -c
).
Upvotes: 2