Error in make command makefile:18: *** missing sep

2020-03-01 03:35发布

For the following make file copied below, I am getting the missing separator error. Nothing seems to be wrong with the tabspace.

OBJS = driver.o snapshot.o
SHOBJS = malloc.o mymemory.o
CC = g++
DEBUG = -g
CFLAGS = -Wall -c $(DEBUG)
LFLAGS = -Wall $(DEBUG)
Snapshot: $(OBJS)
  $(CC) $(LFLAGS) $(OBJS) -o Snapshot
driver.o: snapshot.h driver.cpp
  $(CC) $(CFLAGS) driver.cpp
snapshot.o: mymemory.h snapshot.h snapshot.cpp
  $(CC) $(CFLAGS) snapshot.cpp
libmymemory.so: $(SHOBJS)
  gcc -shared -o libmymemory.so malloc.o mymemory.o
malloc.o: malloc.c
  gcc -fPIC -g -c -Wall malloc.c
mymemory.o: mymemory.cpp
 gcc -fPIC -g -c -Wall mymemory.cpp 
clean:
 \rm *.o *~ Snapshot

4条回答
虎瘦雄心在
2楼-- · 2020-03-01 04:15

Line 18 is gcc -fPIC -g -c -Wall mymemory.cpp. Make is expecting a separator, typically :. It's not detecting this line as a command. You mistyped the intendation: you have spaces where you should have a tab.

Good editors highlight makefile lines that begin with spaces but look like they should begin with a tab instead.

查看更多
仙女界的扛把子
3楼-- · 2020-03-01 04:19

This mostly happens if you copy paste the code from internet. Remove all the spaces from the indented lines by using the delete key. And then press the tab key, only once per line.

Save it and try running the file again. It should work now. This worked for me.

查看更多
相关推荐>>
4楼-- · 2020-03-01 04:32

I have seen this error message when a file used spaces instead of tab character(s) at the beginning of a line in the makefile.

查看更多
Explosion°爆炸
5楼-- · 2020-03-01 04:36

I don't know if it's accurate or an artifact of pasting the code online, but the indentation for the last two commands in the file looks like it's smaller than the commands above it. Double-check your spacing carefully.

查看更多
登录 后发表回答