Post

Troubleshooting Makefile Missing Separator Error in VSC

Troubleshooting Makefile Missing Separator Error in VSC

Background on Makefiles

Recently, I’ve learned about Makefiles (Thanks again to Slava). Make is a command line tool, typically used for compiling and maintaining code for software in languages like C and C++. The Makefile serves as a sort of “recipe” for building the program that lists rules or specific commands for it.

Makefiles can also be used for storing common commands. For example, I made one on this blog since I had to repeatedly type the command below to test my blog locally:

1
bundle exec jekyll serve

Now with the code below in my Makefile, I can simply run make local to test this website instead of typing out bundle exec jekyll serve every time. This works somewhat similar to how aliases in bash work.

1
2
local:
	bundle exec jekyll serve

Troubleshooting Missing Separator Error

However, whenever I tried running make local in Visual Studio Code, I ran into an error that said “missing separator”: Makefile-Missing-Separator.png

I started looking up solutions, and a Stackoverflow poster linked the GNU make utility documentation that stated, “a tab character needs to be at the beginning of every recipe line”.

The poster then suggested using the bash command below to see where the line endings and tabs are:

1
cat -e -t -v Makefile

The cat command in unix is used for displaying file contents or concatenating files. The options after cat ensure that new lines, tabs, and non-printing characters are also displayed in the output. (Source: Linux manual page on cat command)

  • -e, displays $ at the end of each line
  • -t, displays ^I for every TAB character
  • -v, displays ^ and M- for non-printing characters

A comment on the original Stackoverflow answer found a way to make the command even shorter:

1
cat -A Makefile
  • -A, combines the -e, -t, and -v options from above

Solution

After using cat -A Makefile, this was my output:

1
2
local:$
	bundle exec jekyll serve$

Despite using the tab button to indent the 2nd line, there was no ^I before bundle. That meant that my IDE (Visual Studio Code) was using spaces to indent. I used this YouTube video to learn how to convert indentation to tabs in VSC:

After changing that option in Visual Studio Code and putting the tab characters into the Makefile, this was my new output for cat -A Makefile:

1
2
local:$
^Ibundle exec jekyll serve$

The ^I was there, which got rid of the missing separator error! This now allows me to use my Makefile for storing commands.

This post is licensed under CC BY 4.0 by the author.