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
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With