Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make: *** No rule to make target `gcc', needed by `all'. Stop

Tags:

c

makefile

I am going through an eg pgm to create a make file.

http://mrbook.org/tutorials/make/

My folder eg_make_creation contains the following files,

desktop:~/eg_make_creation$ ls
factorial.c  functions.h  hello  hello.c  main.c  Makefile

Makefile

all:gcc -c main.c hello.c factorial.c -o hello

error:

desktop:~/eg_make_creation$ make all
make: *** No rule to make target `gcc', needed by `all'.  Stop.

Please help me understand to compile this program.

like image 357
Angus Avatar asked Dec 19 '11 09:12

Angus


2 Answers

The syntax of makefiles is very strict:

target:dependencies
        build_rules
# ^ this space here _needs_ to be a tab.

What you wrote makes all depend on gcc, -c, ... which are not valid targets.

What you need is something like:

all: hello

hello: factorial.c  functions.h hello.c  main.c 
         gcc -o hello factorial.c hello.c  main.c 

(If you want to compile and link in one step, don't use the -c switch).

like image 56
Mat Avatar answered Nov 05 '22 09:11

Mat


Mat nailed it.

In my particular case, I'm using vi and have the expandtab enabled by default!!

To see if this issue applies to you, open vi and do:

:set list

If you don't see a ^I where a tab should be, then you most likely have the et enabled.

To disabled it just:

:set expandtab!

Maybe it helps somebody else as well.

like image 42
mimoralea Avatar answered Nov 05 '22 08:11

mimoralea