0

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

Jack
  • 9
  • 1
  • 1
  • You should be using tabs. Are you sure your editor didn't convert them to spaces? – HolyBlackCat Nov 28 '21 at 19:08
  • I have this error sometimes, I think it has to do with the indentation going bad sometimes. – Scouarn. Nov 28 '21 at 19:09
  • Just to make it clear, the `${CC)` lines should be indented with tabs. – Bib Nov 28 '21 at 19:09
  • You can learn about makefiles by reading the manual: https://www.gnu.org/software/make/manual/html_node/Introduction.html As mentioned here, the recipe (compiler commands in this makefile) must be indented with a true TAB character. Most likely your editor is converting this to spaces before saving the file. If you are on Linux or using Git for Windows shell you can run `cat -t Makefile` and it will show your TAB chars a `^I`. If you don't see that at the start of your `$(CC)` lines that's your problem. – MadScientist Nov 28 '21 at 19:14
  • Does this answer your question? [makefile:4: \*\*\* missing separator. Stop](https://stackoverflow.com/questions/16931770/makefile4-missing-separator-stop) – Renaud Pacalet Nov 29 '21 at 09:16
  • A good way to solve your problems, even before asking questions, is simply to search for your error message in SO. This "_missing separator_" question is probably the most asked one about makefiles. – Renaud Pacalet Nov 29 '21 at 09:18

2 Answers2

1

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.

T0maas
  • 422
  • 2
  • 12
1

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 :)

  • could you explain how to do that? Do I jus type that in my console? – Jack Nov 28 '21 at 20:04
  • GNUmakefile mode of emacs help me to edit Makefiles alot without needed to check Makefile manually in console with cat and so on. Perhaps you have similar function/feature in your editor/ide, you have only to activate? – – Clas Onnebrink Nov 28 '21 at 20:38