Home > Mobile >  Makefile:6: *** missing separator. Stop. Error
Makefile:6: *** missing separator. Stop. Error

Time:11-29

I have the makefile code

CC = gcc
CFLAGS = -I. -g -pthread -w
DEPS = main.h
OBJ = main.o
%.o: %.c $(DEPS)
  $(CC) -c -o $@ $< $(CFLAGS)

main: $(OBJ)
  $(CC) -o $@ $^ $(CFLAGS)

This is for an assignment on multithreading; I have one main function in a main.c file and one main function in a randomgen.c file. I also have a main.h file and a .txt file that it can read from if any of that matters. I tried looking up what to do earlier and read about it being particular to spaces/tabs. I've tried what seems like every iteration of tabs and/or spaces and I keep getting the same problem. I also don't have a great understanding of makefiles, as it's something our professor never really explained, just kinda incorporated into assignments. Thanks for any help

CodePudding user response:

Separator in makefile is Tab. So your makefile should contain tabs as separator when writing command

CC = gcc
CFLAGS = -I. -g -pthread -w
DEPS = main.h
OBJ = main.o
%.o: %.c $(DEPS)
<TAB>$(CC) -c -o $@ $< $(CFLAGS)

main: $(OBJ)
<TAB>$(CC) -o $@ $^ $(CFLAGS)

If you are not sure if your makefile containt tab or spaces, view it in hex editor. If it contains tabs you will see 09 hex code. 09 hex is tab.

CodePudding user response:

You can proof it with:

cat -e -t -v Makefile




 clas@ertdev clbc > make clean
    Makefile:92: *** missing separator.  Stop.

Now i type in console:

cat -e -t -v Makefile

then i see

$(OBJFILESTST): $(SRCFILESTST)$
 @mkdir -p $(OUTDIROBJ)$
^I$(call get_source_file,$@,$^,$<)$
^I@ $(BUILDCXX) $(CXXFLAGSTST) -c $(REAL_SRC_FILE) -o $@$

before @mkdir you can see non printing tab is missing: After if fixed it and typed it again in console:

$(OBJFILESTST): $(SRCFILESTST)$
^I@mkdir -p $(OUTDIROBJ)$
^I$(call get_source_file,$@,$^,$<)$
^I@ $(BUILDCXX) $(CXXFLAGSTST) -c $(REAL_SRC_FILE) -o $@$

make is running again without missing separator exception. But normally my editor (Emacs) helps me with this kind of problems :)

  • Related