93

Possible Duplicate:
Make error: missing separator

Have this code in makefile:

PROG = semsearch
all: $(PROG)
%: %.c
gcc -o $@ $< -lpthread

clean:
rm $(PROG)

and the error

missing separator. stop.

Can someone help me?

Community
  • 1
  • 1
user1827257
  • 1,600
  • 4
  • 17
  • 24
  • 3
    Indentation is not optional in Makefiles. Is what you have exactly as you posted it or did whitespace get munged? – Mat Jan 01 '13 at 10:44
  • 9
    This question should be reopened. The answer here also shows how to write a Makefile without tabs, completely circumventing the problem. – Jens Sep 12 '13 at 06:32

1 Answers1

239

You need to precede the lines starting with gcc and rm with a hard tab. Commands in make rules are required to start with a tab (unless they follow a semicolon on the same line). The result should look like this:

PROG = semsearch
all: $(PROG)
%: %.c
        gcc -o $@ $< -lpthread

clean:
        rm $(PROG)

Note that some editors may be configured to insert a sequence of spaces instead of a hard tab. If there are spaces at the start of these lines you'll also see the "missing separator" error. If you do have problems inserting hard tabs, use the semicolon way:

PROG = semsearch
all: $(PROG)
%: %.c ; gcc -o $@ $< -lpthread

clean: ; rm $(PROG)
Jens
  • 69,818
  • 15
  • 125
  • 179
  • 3
    You can use .RECIPEPREFIX to change the character make uses. See: https://www.gnu.org/software/make/manual/html_node/Special-Variables.html#Special-Variables – aseq Dec 01 '16 at 09:29