C语言 Makefile:1: *** 缺少分隔符。停止

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18936337/
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 07:31:00  来源:igfitidea点击:

Makefile:1: *** missing separator. Stop

cmakefile

提问by Jo?o Miranda

I'm creating a project on c and when i make my Makefile and try to run it it gives me this error:

我在 c 上创建一个项目,当我制作我的 Makefile 并尝试运行它时,它给了我这个错误:

Makefile:1: *** missing separator.  Stop.

My makefile code is:

我的生成文件代码是:

CC=gcc
OBJ=./objetos
INC=./include
FON=./aqsFonte
BIB=./bibliotecas
OPBIB=-lBiblioteca
ProjetoFinal: libFinal.a 
    $(CP) $(FON)/ProjetoFinal.c -I$(INC) -L$(BIB) $(OPBIB) -o ProjetoFinal

Bibliotecas.a: Caminho.o Libs_Defines.o Matrizes.o Proc_Imagens.o Vetores.o
    ar -q $(BIB)/libFinal.a Caminho.o ibs_Defines.o Matrizes.o Proc_Imagens.o Vetores.o

Caminho.o:
    $(CP) $(FON)/Caminho.c -o Caminho.o
Libs_Defines.o :
    $(CP) $(FON)/Libs_Defines.c -o Libs_Defines.o
Matrizes.o:
    $(CP) $(FON)/Matrizes.c -o Matrizes.o
Proc_Imagens.o: 
    $(CP) $(FON)/Proc_Imagens.c -o Proc_Imagens.o
Vetores.o:
    $(CP) $(FON)/Vetores.c -o Vetores.o

Also, it's all tabbed correctly I guess.

此外,我猜这一切都已正确标记。

回答by Filipe Gon?alves

It's a tabs problem. Some text editors may replace tabs with white spaces, make sure you use a proper text editor that doesn't mess it up. Open your makefile in vi or any other rudimentary editor, and rewrite that makefile.

这是标签问题。某些文本编辑器可能会用空格替换制表符,请确保使用不会弄乱的合适的文本编辑器。在 vi 或任何其他基本编辑器中打开您的 makefile,并重写该 makefile。

Note that after each target rule, one single tabmust be placed in the beginning of the line. Everything that comes after that tab is passed on to the shell (there can be more tabs, spaces, and whatever you want, but keep in mind that there must be a tab in the beginning of the line).

请注意,在每个目标规则之后,必须在行的开头放置一个选项卡。该制表符之后的所有内容都传递给外壳程序(可以有更多制表符、空格和任何您想要的,但请记住,该行的开头必须有一个制表符)。

回答by Leeor

can you try running -

你可以试试跑步吗 -

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

(after saving a backup of course)

(当然保存备份后)

回答by Andreas Grapentin

make is very sensitive on the way rules and targets are indented. The error you post is usually caused by indenting the rule of a target with spaces instead of a single tab.

make 对规则和目标的缩进方式非常敏感。您发布的错误通常是由使用空格而不是单个制表符缩进目标规则引起的。

for example:

例如:

target:
    do stuff

will error, but

会出错,但是

target:
<tab>do stuff

will not.

将不会。

回答by avinash k

actually i faced a similar problem every thing was right but later i understood i use g-edit ill tell the solution edit>preferances>editor tab>uncheck the button (insert spaces instead of tabs) and it worked just fine

实际上我遇到了类似的问题,每一件事都是对的,但后来我明白我使用 g-edit 告诉解决方案编辑>首选项>编辑器选项卡>取消选中按钮(插入空格而不是选项卡),它工作得很好

回答by BrainSlugs83

You're probably using a modern text editor that understands the unicode standard. -- Even if you open an ANSI file in these editors, they'll usually save them back out as UTF-8 -- which is very backwards compatible, except that it places two "invisible" bytes at the beginning of the file, so that other programs will know what format the text is encoded with. -- This is why the "error" is reported on line 1.

您可能正在使用理解 unicode 标准的现代文本编辑器。-- 即使你在这些编辑器中打开一个 ANSI 文件,它们通常也会将它们保存为 UTF-8 -- 这是非常向后兼容的,除了它在文件的开头放置了两个“不可见”字节,所以其他程序将知道文本的编码格式。-- 这就是第 1 行报告“错误”的原因。

If you're using Notepad for Windows, you're in luck, as there is an option to override this behavior and save the file in the "ANSI" format. Here's how:

如果您使用的是 Windows 版记事本,那么您很幸运,因为有一个选项可以覆盖此行为并将文件保存为“ANSI”格式。就是这样:

  1. File -> Save As
  2. Change "Save as type" to "All Files".
  3. Find the exact location of the Makefile (sometimes, save as puts you in a different directory, I don't know why this happened but it kept happening to me).
  4. Change the file name from "Makefile" to "Makefile." -- the trailing period is important (without it, it will be saved as "Makefile.txt", even when "All Files" is selected).
  5. Change "Encoding" from "UTF-8" to "ANSI".

    Save with ANSI Encoding

  1. 文件 -> 另存为
  2. 将“保存类型”更改为“所有文件”。
  3. 找到 Makefile 的确切位置(有时,另存为会将您放在不同的目录中,我不知道为什么会发生这种情况,但它一直发生在我身上)。
  4. 将文件名从“Makefile”更改为“Makefile”。-- 尾随句点很重要(没有它,即使选择了“所有文件”,它也会保存为“Makefile.txt”)。
  5. 将“编码”从“UTF-8”更改为“ANSI”。

    使用 ANSI 编码保存

回答by jeffersonpig

I just meet the same problem when compliling my source code with auto generated gcc makefile.

在使用自动生成的 gcc makefile 编译我的源代码时,我遇到了同样的问题。

I finally found it was caused by the utf-8 BOM characters at the beginning of the makefile.These charaters are invisible in some text editors.

终于发现是makefile开头的utf-8 BOM字符造成的。这些字符在一些文本编辑器中是不可见的。

so try save the file as utf-8 without BOM.

所以尝试将文件保存为没有 BOM 的 utf-8。