92

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 !!

5
  • 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.) Commented May 29, 2014 at 6: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. Commented May 29, 2014 at 6: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 Commented May 29, 2014 at 6:47
  • 3
    Please verify you're using tabs instead of spaces
    – Sorcrer
    Commented May 29, 2014 at 7:30
  • 1
    I had also same issue but using different editor i have tried it give tab and its working. Commented Jul 22, 2017 at 9:30

1 Answer 1

197

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
2
  • 1
    why would the error message not say this?
    – julz12
    Commented Mar 3, 2023 at 13:46
  • In my VS Code editor, all is space-centric, so that semicolon option is gold. TY.
    – Wellspring
    Commented May 17 at 13:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.