Rahul Reddy
Rahul Reddy

Reputation: 13153

makefile:4: *** missing separator. Stop

This is my makefile:

all:ll

ll:ll.c   
  gcc  -c  -Wall -Werror -02 c.c ll.c  -o  ll  $@  $<

clean :
  \rm -fr ll

When I try to make clean or make make, I get this error:

:makefile:4: *** missing separator.  Stop.

How can I fix it?

Upvotes: 874

Views: 1002620

Answers (19)

Michael Nelles
Michael Nelles

Reputation: 5992

For me 2023 only this worked. enter image description here

After this everything worked fine.

Upvotes: 13

Arshid KV
Arshid KV

Reputation: 10037

Try with the following command.

perl -pi -e 's/^ */\t/' Makefile

Upvotes: 4

 Lonedone
Lonedone

Reputation: 29

If someone ever comes across this issue with

*** missing separator.  Stop.

during the build, they should double-check their file system path to the sources, it should not contain special characters like "#"

e.g. path

/home/user/#my_sources/

might be invalid

Upvotes: 1

Denny Mathew
Denny Mathew

Reputation: 1132

By default, you should always write command after a Tab and not white space. This can be changed to another character with .RECIPEPREFIX variable.

This applies to gcc line (line #4) in your case. You need to insert tab before gcc.

Also replace \rm -fr ll with rm -fr ll. Insert tabs before this command too.

Upvotes: 67

Nitin4873
Nitin4873

Reputation: 17552

make defines a tab is required to start each recipe. All actions of every rule are identified by tabs. If you prefer to prefix your recipes with a character other than tab, you can set the .RECIPEPREFIX variable to an alternate character.

To check, I use the command cat -e -t -v makefile_name.

It shows the presence of tabs with ^I and line endings with $. Both are vital to ensure that dependencies end properly and tabs mark the action for the rules so that they are easily identifiable to the make utility.

Example:

Kaizen ~/so_test $ cat -e -t -v  mk.t
all:ll$      ## here the $ is end of line ...                   
$
ll:ll.c   $
^Igcc  -c  -Wall -Werror -02 c.c ll.c  -o  ll  $@  $<$ 
## the ^I above means a tab was there before the action part, so this line is ok .
 $
clean :$
   \rm -fr ll$
## see here there is no ^I which means , tab is not present .... 
## in this case you need to open the file again and edit/ensure a tab 
## starts the action part

Upvotes: 1664

hesam rajaei
hesam rajaei

Reputation: 358

When you created a Makefile in VSCode, You should set the Tab Size: 4enter image description here.

Upvotes: 13

Jan Klan
Jan Klan

Reputation: 874

Do yourself a favour and make this a permanent member of your .editorconfig, if your editor/IDE supports it (it probably does!)

[Makefile]
indent_style = tab

Upvotes: 3

WeezyKrush
WeezyKrush

Reputation: 494

TLDR;

makefile syntax can be quirky
if you want a line of code to be interpreted as make code it must only be indented with spaces.
if you want a line of code to be interpreted as bash code it must only be indented with tabs

sometask:
  ifeq ($FOO,bar)  // this is make code. only spaces
    echo "foobar"  // this is bash code. only tabs
  endif            // again, this is make code. only spaces

technically its the leading indentation that dictates the interpreter.

Upvotes: 23

wlsherica
wlsherica

Reputation: 577

The key point was "HARD TAB"

  1. Check whether you used TAB instead of whitespace
  2. Check your .vimrc for set tabstop=X

Upvotes: 5

Petr Kosvanec
Petr Kosvanec

Reputation: 119

You started line 4 with "space,space" instead of "tab" - nothing else.

Upvotes: 8

Yonas Kassa
Yonas Kassa

Reputation: 3690

If you are here searching how to make the tabs and new lines you added understandable by vim you have to first enable tab in vim.

You can do it using :set noet i.e. (to switch from spaces to TAB) before you make your tab additions.

With this command your tabs will look like the other ones (i.e. ^I) and *** missing separator. Stop. error from make will go away :)

after you make changes you can switch back with :set et

Upvotes: 2

Rose
Rose

Reputation: 2872

If you are editing your Makefile in eclipse:

Windows-> Preferences->General->Editor->Text Editors->Show Whitespace Characters -> Apply

Or use the shortcut shown below.

Tab will be represented by gray ">>" and Space will be represented by gray "." as in figure below.

enter image description here

Upvotes: 0

Daniel W.
Daniel W.

Reputation: 32260

Using .editorconfig to fix the tabs automagically:

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab

Upvotes: 16

Tomasz Bartkowiak
Tomasz Bartkowiak

Reputation: 14948

The solution for PyCharm would be to install a Makefile support plugin:

  1. Open Preferences (cmd + ,)
  2. Go to Plugins -> Marketplace
  3. Search for Makefile support, install and restart the IDE.

This should fix the problem and provide a syntax for a makefile.

Upvotes: 20

X zheng
X zheng

Reputation: 1971

If you are using mcedit for makefile edit. you have to see the following mark. enter image description here

Upvotes: 2

If anyone of you are using a product from Intellij, the solution for this it's the following:

  1. Go to Preferences > Editor > Code Style
  2. here you need to select the file type related to your problem. But most probably you need to select Other File Types.
  3. In the tab opened mark the checkbox for Use tab character and be careful, Tab size and Indent values must be 4.

Upvotes: 5

Panch
Panch

Reputation: 1187

Its pretty old question but still I would like say about one more option using vi/vim editor to visualize the tabs. If you have vi/vim installed then open a Makefile (e.g. vim Makefile) and enter :set list. This will show number of tabs inserted as below,

 %-linux: force$
^I@if [ "$(GCC_VERSION)" = "2.96" ] ; then \$
^I^Iecho ===== Generating build tree for legacy $@ architecture =====; \$
^I^I$(CONFIGURE) $(CWD) $@ legacy; \$
^Ielse \$
^I^Iecho ===== Generating build tree for $@ architecture =====; \$
^I^I$(CONFIGURE) $(CWD) $@; \$
^Ifi$
^Icd build-$@;make$

Upvotes: 9

Shrinivas Patgar
Shrinivas Patgar

Reputation: 121

This is because tab is replaced by spaces. To disable this feature go to

gedit->edit->preferences->editor

and remove check for

"replace tab with space"

Upvotes: 2

Alan
Alan

Reputation: 1832

On VS Code, just click the "Space: 4" on the downright corner and change it to tab when editing your Makefile.

Upvotes: 139

Related Questions