This is my makefile:
all:ll
ll:ll.c
gcc -c -Wall -Werror -02 c.c ll.c -o ll [email protected] $<
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?
12 Answers
make has a very stupid relationship with tabs. All actions of every rule are identified by tabs. And, no, four spaces don’t make a tab. Only a tab makes a tab.
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 [email protected] $<$
## 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
On VS Code, just click the “Space: 4” on the downright corner and change it to tab when editing your Makefile.
You should always write command after a Tab and not white space.
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.
The solution for PyCharm
would be to install a Makefile support
plugin:
- Open
Preferences
(cmd + ,
) - Go to
Plugins
->Marketplace
- Search for
Makefile support
, install and restart the IDE.
This should fix the problem and provide a syntax for a makefile.
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
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$
^[email protected] [ "$(GCC_VERSION)" = "2.96" ] ; then $
^I^Iecho ===== Generating build tree for legacy [email protected] architecture =====; $
^I^I$(CONFIGURE) $(CWD) [email protected] legacy; $
^Ielse $
^I^Iecho ===== Generating build tree for [email protected] architecture =====; $
^I^I$(CONFIGURE) $(CWD) [email protected]; $
^Ifi$
^Icd [email protected];make$
The key point was “HARD TAB” 1. Check whether you used TAB instead of whitespace 2. Check your .vimrc for “set tabstop=X”
If anyone of you are using a product from Intellij, the solution for this it’s the following:
- Go to Preferences > Editor > Code Style
- here you need to select the file type related to your problem. But most probably you need to select
Other File Types
. - In the tab opened mark the checkbox for
Use tab character
and be careful,Tab size
andIndent
values must be 4.
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”
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.
Your version of Linux doesn’t support this kind of functionality please go for another suitable version i.e. Kali Linux or Red Hat.