Robert777
Robert777

Reputation: 801

What is wrong with this Makefile?

I'm trying to learn how to use makefiles in Ubuntu with C (I'm a beginner as you might guess). There is a chapter about this subject in "A Book on C" and they gave a simple example of 3 files: main.c, sum.c, sum.h (without code) and a makefile with this code:

sum: main.o sum.o
    gcc –o sum main.o sum.o
main.o: main.c sum.h
    gcc –c main.c 
sum.o: sum.c sum.h
    gcc –c sum.c 

Now, I am trying to compile this code in eclipse but it doesn't work. I've created a file named makefile with the code above and the 3 files that I mentioned earlier. This is the error that I get:

make all 
make: *** No rule to make target `all'.  Stop.

I would appreciate any help. Thanks

Upvotes: 1

Views: 232

Answers (1)

Jah
Jah

Reputation: 1039

Running 'make all', means that you are trying to build a target called 'all', but you haven't defined one.

You need to add in the first line:

all: sum

BTW, if you'll run 'make' (without an argument), it will build the first target (if there's no 'all' target). That's why I advise you to put the 'all' target as the first one.

Upvotes: 7

Related Questions