C语言 makefile:4: *** 缺少分隔符。停止

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16931770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 06:34:58  来源:igfitidea点击:

makefile:4: *** missing separator. Stop

cmakefile

提问by Rahul Reddy

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 cleanor make make, I get this error:

当我尝试make clean或 时make make,出现此错误:

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

How can I fix it?

我该如何解决?

回答by nitin

makefile has a very stupid relation with tabs, all actions of every rule are identified by tabs. And no, 4 spaces don't make a tab, only a tab makes a tab.

makefile 与制表符的关系非常愚蠢,每个规则的所有操作都由制表符标识。不,4 个空格不能构成制表符,只有制表符才能构成制表符。

to check I use the command cat -e -t -v makefile_name

检查我使用命令 cat -e -t -v makefile_name

It shows the presence of tabs with ^Iand 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.

它显示了选项卡的存在^I和行结尾$对确保依赖关系正确结束至关重要,选项卡标记规则的操作,以便 make 实用程序可以轻松识别它们。

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

回答by alanwsx

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

在 VS Code 上,只需单击右下角的“Space: 4”并在编辑 Makefile 时将其更改为选项卡。

回答by Denny Mathew

You should always write command after a Taband not white space.

你应该总是在 aTab而不是空格之后写命令。

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

gcc在您的情况下,这适用于行(第 4 行)。您需要在gcc.

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

也替换\rm -fr llrm -fr ll. 在此命令之前也插入制表符。

回答by Tomasz Bartkowiak

The solution for PyCharmwould be to install a Makefile supportplugin:

解决方案PyCharm是安装一个Makefile support插件:

  1. Open Preferences(cmd + ,)
  2. Go to Plugins-> Marketplace
  3. Search for Makefile support, install and restart the IDE.
  1. 打开Preferences( cmd + ,)
  2. Plugins->Marketplace
  3. 搜索Makefile support、安装并重新启动 IDE。

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

这应该可以解决问题并为生成文件提供语法。

回答by Panch

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

这是一个很老的问题,但我仍然想说一个使用vi/vim编辑器可视化选项卡的选项。如果您已vi/vim安装,则打开Makefile(例如vim Makefile)并输入:set list. 这将显示插入的选项卡数量,如下所示,

 %-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$

回答by Daniel W.

Using .editorconfigto fix the tabs automagically:

使用.editorconfig,自动将修复标签:

root = true

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

[Makefile]
indent_style = tab

回答by wlsherica

The key point was "HARD TAB" 1. Check whether you used TAB instead of whitespace 2. Check your .vimrc for "set tabstop=X"

关键点是“HARD TAB” 1. 检查您是否使用 TAB 而不是空格 2. 检查您的 .vimrc 中的“set tabstop=X”

回答by Bogdan Alexandru Militaru

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

如果你们中的任何人使用 Intellij 的产品,则解决方案如下:

  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 characterand be careful, Tab sizeand Indentvalues must be 4.
  1. 转到首选项 > 编辑器 > 代码样式
  2. 在这里您需要选择与您的问题相关的文件类型。但很可能您需要选择Other File Types.
  3. 在打开的标签标志着该复选框Use tab character,小心,Tab sizeIndent值必须是4。

回答by riguang zheng

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

如果您使用 mcedit 进行 makefile 编辑。您必须看到以下标记。 在此处输入图片说明

回答by Shrinivas Patgar

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

这是因为制表符被空格替换了。要禁用此功能,请转到

gedit->edit->preferences->editor

gedit->编辑->首选项->编辑器

and remove check for

并删除检查

"replace tab with space"

用空格替换制表符