Makefile - missing separator

MakefileGnu Make

Makefile Problem Overview


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

Makefile Solutions


Solution 1 - Makefile

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)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1827257View Question on Stackoverflow
Solution 1 - MakefileJensView Answer on Stackoverflow