88

I have two .cpp files namely decryptor.cpp and prod-ent.cpp.
I have created a Makefile to for the compilation of both the files in Linux platform.

all: decryptor.cpp prod-ent.cpp
       g++ prod-ent.cpp -o prod-ent -g
       g++ decryptor.cpp -o decryptor -g -lcryptopp
clean:
       rm prod-ent
       rm decryptor

Whenever I'm trying to execute the Makefile its showing me the following error:

Makefile:2: * missing separator. Stop.

I am new to create makefiles and cannot figure out my fault. Please help me in correcting the code.

Thanks in advance !!

Tom Tanner
  • 9,244
  • 3
  • 33
  • 61
user3686363
  • 891
  • 1
  • 6
  • 4
  • 6
    Indentation matters in Makefiles, so please make sure to post an accurate representation. What you posted looks wrong (leading spaces before targets, `all` and `clean` misaligned.) – juanchopanza May 29 '14 at 06:38
  • 1
    I remember having this problem with manually-generated makefiles a few times... I think you need to use a tab character to indent the compilation commands, rather than a series of spaces. – rainbowgoblin May 29 '14 at 06:44
  • Tabs are given in front of "g++"s and "rm"s in all the occurrences and a space is given between the two file-names and in between the options. Still it doesn't work – user3686363 May 29 '14 at 06:47
  • 3
    Please verify you're using tabs instead of spaces – Sorcrer May 29 '14 at 07:30
  • 1
    I had also same issue but using different editor i have tried it give tab and its working. – Kalarav Parmar Jul 22 '17 at 09:30

1 Answers1

191

You need a real tab instead of space in front of g++ and rm commands. If still fails then your editor is inserting spaces instead, even if you're hitting the tab key on your keyboard. You need to configure your editor to insert hard tabs (09 in ASCII) instead.

Like

all: decryptor.cpp prod-ent.cpp
*****g++ prod-ent.cpp -o prod-ent -g
*****g++ decryptor.cpp -o decryptor -g -lcryptopp
clean:
*****rm prod-ent
*****rm decryptor

Instead ***** replace TAB.

You can check your side by command

cat -e -t -v  makefile

It's show line starting by ^I if TAB is given to that line and it end the line by $.

Also you can do by ;

all: decryptor.cpp prod-ent.cpp ; g++ prod-ent.cpp -o prod-ent -g ; g++ decryptor.cpp -o decryptor -g -lcryptopp
clean: ; rm prod-ent ; rm decryptor
Jayesh Bhoi
  • 24,694
  • 15
  • 58
  • 73