Makefile:27: *** missing separator (did you mean TAB instead of 8 spaces?). Stop. on…
- User
Makefile:27: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.
on
Makefile
Compiler and flags
CC = gcc CFLAGS = -Wall -Wextra -g -I$(SRC_DIR)
Directories
SRC_DIR = src SIM_DIR = src/simulations BUILD_DIR = build LOG_DIR = logs
Source files
SRC_FILES = (SRC_DIR)/reporter.c
(SRC_DIR)/error_handler.cSimulation executables
SIMULATIONS = simulate_memory_error simulate_file_error simulate_device_error
Default target
all: mkdirs $(SIMULATIONS)
Create necessary directories
mkdirs: @mkdir -p (LOG_DIR)
Pattern rule for compiling simulations
(SIM_DIR)/%.c (CC) < @ -lpthread
Clean build and log directories
clean: @rm -rf (LOG_DIR)/*
Phony targets
.PHONY: all clean mkdirs $(SIMULATIONS)
- Assistant
The error message you’re encountering:
Makefile:27: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.indicates that Make expects a tab character at the beginning of line 27 (and likely other command lines in your Makefile), but it found spaces instead. In Makefiles, commands must be indented with a tab, not spaces. Using spaces will cause Make to throw the "missing separator" error.
Identifying the Issue
Let's review the problematic section of your Makefile:
# Create necessary directories mkdirs: @mkdir -p $(BUILD_DIR) $(LOG_DIR) # Pattern rule for compiling simulations $(BUILD_DIR)/%: $(SIM_DIR)/%.c $(SRC_FILES) $(CC) $(CFLAGS) $< $(SRC_FILES) -o $@ -lpthread # Clean build and log directories clean: @rm -rf $(BUILD_DIR)/* $(LOG_DIR)/*In the snippet above, the lines starting with
@mkdir,$(CC), and@rm -rfare indented with spaces. Make requires that these lines start with a single tab character.Correcting the Makefile
Here's the corrected version of your Makefile with tabs replacing the spaces for indentation:
# Makefile # Compiler and flags CC = gcc CFLAGS = -Wall -Wextra -g -I$(SRC_DIR) # Directories SRC_DIR = src SIM_DIR = src/simulations BUILD_DIR = build LOG_DIR = logs # Source files SRC_FILES = $(SRC_DIR)/logger.c \ $(SRC_DIR)/reporter.c \ $(SRC_DIR)/recovery.c \ $(SRC_DIR)/error_handler.c # Simulation executables SIMULATIONS = simulate_memory_error simulate_file_error simulate_device_error # Default target all: mkdirs $(SIMULATIONS) # Create necessary directories mkdirs: @mkdir -p $(BUILD_DIR) $(LOG_DIR) # Pattern rule for compiling simulations $(BUILD_DIR)/%: $(SIM_DIR)/%.c $(SRC_FILES) $(CC) $(CFLAGS) $< $(SRC_FILES) -o $@ -lpthread # Clean build and log directories clean: @rm -rf $(BUILD_DIR)/* $(LOG_DIR)/* # Phony targets .PHONY: all clean mkdirs $(SIMULATIONS)How to Fix It
-
Use a Text Editor That Supports Tabs:
- Ensure you're using a text editor that can insert tab characters. Most code editors (like VSCode, Sublime Text, Atom, or even
vim/nanoon the terminal) support this.
- Ensure you're using a text editor that can insert tab characters. Most code editors (like VSCode, Sublime Text, Atom, or even
-
Replace Spaces with Tabs:
- Go to each command line that should be indented (typically lines under targets like
mkdirs:,$(BUILD_DIR)/%:, andclean:). - Remove the leading spaces.
- Insert a single tab character at the beginning of each command line.
- Go to each command line that should be indented (typically lines under targets like
-
Configure Your Editor:
-
To prevent this issue in the future, configure your editor to use tabs instead of spaces for Makefiles. Some editors allow you to set filetype-specific indentation rules.
-
For example, in VSCode, you can add the following to your
settings.jsonto use tabs for Makefiles:{ "[makefile]": { "editor.insertSpaces": false, "editor.tabSize": 4 } }
-
-
Verify the Fix:
- After making these changes, save the Makefile and try running
makeagain. The error should be resolved.
- After making these changes, save the Makefile and try running
Additional Tips
- Consistent Indentation: Always use consistent indentation (preferably tabs) for command lines in Makefiles.
- Avoid Mixing Tabs and Spaces: Mixing tabs and spaces can lead to hard-to-debug issues. Stick to tabs for indentation in Makefiles.
- Editor Display: Some editors display tabs as multiple spaces (commonly 4 or 8). Ensure that the actual character is a tab, not multiple space characters.
By ensuring that all command lines are properly indented with tabs, your Makefile should work without the "missing separator" error.
-