0

I am using Visual Studio Code and I keep getting the following error message when I use run make: "makefile:20: *** missing separator. Stop." For some reason my indent is not showing up as ^I when I run: cat -e -t -v makefile. Anybody have any ideas? I tried checking the settings of Visual Studio Code and an indent is not replaced with spaces during the build process.

TARGET = shell

CC = gcc

CFLAGS = -Wall -Wextra -std=c99

SOURCES = main.c builtin.c execute.c shell.c

# Define the header files
HEADERS = myheader1.h myheader2.h

# Define the object files
OBJECTS = $(SOURCES:.c=.o) $(HEADERS:.h=.h.gch)

# Define the default target
all: $(TARGET)

# Define the target binary
$(TARGET): $(OBJECTS)
    $(CC) $(CFLAGS) -o $(TARGET) $(OBJECTS)

# Define a pattern rule for building object files
%.o: %.c $(HEADERS)
    $(CC) $(CFLAGS) -I. -c $< -o $@

# Define a pattern rule for building precompiled headers
%.h.gch: %.h
    $(CC) $(CFLAGS) -I. -c $< -o $@

cat -e -t -v makefile

$
CC = gcc$
$
CFLAGS = -Wall -Wextra -std=c99$
$
SOURCES = main.c builtin.c execute.c shell.c$
$
# Define the header files$
HEADERS = myheader1.h myheader2.h$
$
# Define the object files$
OBJECTS = $(SOURCES:.c=.o) $(HEADERS:.h=.h.gch)$
$
# Define the default target$
all: $(TARGET)$
$
# Define the target binary$
$(TARGET): $(OBJECTS)$
    $(CC) $(CFLAGS) -o $(TARGET) $(OBJECTS)$
$
# Define a pattern rule for building object files$
%.o: %.c $(HEADERS)$
    $(CC) $(CFLAGS) -I. -c $< -o $@$
$
# Define a pattern rule for building precompiled headers$
%.h.gch: %.h$
    $(CC) $(CFLAGS) -I. -c $< -o $@$
$
$
$
$
$

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
  • Fancy-shmancy editors like VS Code are notorious for gratuitously replacing whitespaces with tabs, and vice-versa. This utterly reks Makefiles, and other formats that have strict tabbing or whitespace rules. Use what the Wise Gurus expect all C++ developers to use: emacs or vi. The Makefile shown above does not have tabs. Tabs are expected to indent text by 8 positions. The indentations on the rules above are only 4 positions. – Sam Varshavchik Jan 16 '23 at 00:36
  • Duplicates: [0](https://stackoverflow.com/questions/62052345/vs-code-c-programming-how-do-i-fix-makefile2-missing-separator-stop), [1](https://stackoverflow.com/questions/73522642/how-can-i-stop-vs-code-from-converting-tabs-to-spaces-in-a-particular-file), [2](https://stackoverflow.com/questions/16931770/makefile4-missing-separator-stop). – Eric Postpischil Jan 16 '23 at 00:40

0 Answers0