-1

This is my Makefile, I get an error "***missing seperator. stop" I am trying to compile a library but for some reason I get this error message. Other SO questions that are similar suggest that it is a tabbing issue, but i could not solve it.

CC=g++
RANLIB=ranlib

LIBSRC=osm.c 
LIBOBJ=$(LIBSRC:.c=.o)

INCS=-I.
CFLAGS = -Wall -g $(INCS)
LOADLIBES = -L./ 

OSMLIB = libosm.a
TARGETS = $(OSMLIB)

TAR=tar
TARFLAGS=-cvf
TARNAME=ex1.tar
TARSRCS=$(LIBSRC) Makefile README

all: $(TARGETS) 

$(TARGETS): $(LIBOBJ)
$(AR) $(ARFLAGS) $@ $^ //this line fails with the warning
$(RANLIB) $@

clean:
$(RM) $(TARGETS) $(OSMLIB) $(OBJ) $(LIBOBJ) *~ *core

depend:
makedepend -- $(CFLAGS) -- $(SRC) $(LIBSRC)

tar:
$(TAR) $(TARFLAGS) $(TARNAME) $(TARSRCS)
Sharonica
  • 183
  • 1
  • 5
  • 14

3 Answers3

8

Makefile requires that all "commands" in a rule are indented by one tab.

You have, for example, this rule:

clean:
$(RM) $(TARGETS) $(OSMLIB) $(OBJ) $(LIBOBJ) *~ *core

That is wrong, the command-line should be intended with an actual tab (not spaces) like

clean:
    $(RM) $(TARGETS) $(OSMLIB) $(OBJ) $(LIBOBJ) *~ *core
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
2
CC=g++
RANLIB=ranlib

LIBSRC=osm.c 
LIBOBJ=$(LIBSRC:.c=.o)

INCS=-I.
CFLAGS = -Wall -g $(INCS)
LOADLIBES = -L./ 

OSMLIB = libosm.a
TARGETS = $(OSMLIB)

TAR=tar
TARFLAGS=-cvf
TARNAME=ex1.tar
TARSRCS=$(LIBSRC) Makefile README

all: $(TARGETS) 

$(TARGETS): $(LIBOBJ)
     $(AR) $(ARFLAGS) $@ $^ //this line fails with the warning
     $(RANLIB) $@

clean:
     $(RM) $(TARGETS) $(OSMLIB) $(OBJ) $(LIBOBJ) *~ *core

depend:
     makedepend -- $(CFLAGS) -- $(SRC) $(LIBSRC)

tar:
     $(TAR) $(TARFLAGS) $(TARNAME) $(TARSRCS)
ntshetty
  • 1,293
  • 9
  • 20
0

make files have a specific structure and syntax. Generally:

<target> : <dependencies>
<tab><instructions>

The tab at the start of the line is part of the syntax.

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458