ChatGPT解决这个技术问题 Extra ChatGPT

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?

You can use .RECIPEPREFIX to change the character make uses. See: gnu.org/software/make/manual/html_node/…
How was this not closed as a duplicate??? Possible duplicate of Make error: missing separator
In the mcedit "Options -> General" make shure that "Fake half tabs" do not have "X" in square brackets before that option.
In vim, use: Ctrl+V + Tab

E
Efren

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

"cat -e -t -v makefile_name" is the best thing. Ever. I kept staring at the screen, seeing what looked like a tab, totally missing that it is the ONE LINE in the entire file which used spaces instead of a hard tab.
When copy/pasting from one makefile to another using the vi (or vim) editor be sure not to accidentally grab the ~ (tilde) line indicating end of file. A real ~ looks like a vi marker and will cause the "*** missing separator. Stop." error. This may seem obvious but when it happens accidentally it's far from evident. See my blog commentary for more information.
-v option for cat command is redundant here because -e means -vE and -t means -vT.
It's no more "stupid" than Python needing whitespace for control flow, or C needing identifiers made up of certain characters, or English needing vowels. It's just a rule.
@JuhaUntinen no, it has never changed and no, it does not work just as well.
S
S. Wu

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


VS Code recognised that my 'common.mk' file, extracted from a no-suffix 'Makefile' was a make file, and highlighted it correctly - but quietly started indenting with spaces instead of tabs.
This worked when I selected "Convert Indentation to Tabs"
E
Efren

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.


To be very clear, there must be a hard TAB character as the first character in each logical recipe line. After the TAB, you can add any kind of whitespace you want.
should the tabspace be equal to 2 or 4? in /.vimrc set tabstop = 2 or 4?
@RahulReddy how an editor displays a tab has nothing to do with whether there is or is not a tab character in the configuration.
T
Tomasz Bartkowiak

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.


This also helps in GoLand
I find IDE real matters. Tab edition is not supported in pycharm. When I change to ATOM, TAB input works.
If your IDE is automatically indenting with spaces, you might be able to enter a unicode tab with \u09 which on some desktop environments for Linux can be done with Ctrl+Shift+U then typing '09'. " ". It isn't very fun though.
D
Daniel W.

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

not working for me
@TejasShetty it's not meant to work for a person but for the IDE ;-) If it doesn't work for you, you need to enable it in your IDE.
W
WeezyKrush

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.


P
Panch

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$

P
Petr Kosvanec

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


B
Bogdan Alexandru Militaru

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 and Indent values must be 4.


D
Daniel W.

The key point was "HARD TAB"

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


r
riguang zheng

https://i.stack.imgur.com/5uuPV.png


h
hesam rajaei

https://i.stack.imgur.com/EJX2C.png


M
Mansuro

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"


y
yosemite_k

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


R
Rose

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.

https://i.stack.imgur.com/CrXbB.png


j
jtony

Use -A or --show-all to show everything for simplicity.


what? care to explain?
J
Jan Klan

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

L
Lonedone

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


Could you please give more details?
The issue generally happens when you use spaces in place of Tab. In most editors there will be a setting to change the Tab to spaces conversion. That need's to be disabled or one can use notepad++ or sublime text to replace all spaces before rules with tabs.
I'm not sure what you guys mean and what details you want. My answer is related to the path to the sources, in my case, the problem was that the file system path contained the special character "#" and the problem was not related to the content of the sources itself and there was no mention of that potential problem in other answers. The problem with spaces is already elaborated on in other answers.