45

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

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.

Software Engineer
  • 15,457
  • 7
  • 74
  • 102
João Miranda
  • 487
  • 1
  • 5
  • 12

8 Answers8

59

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.

Note that after each target rule, one single tab must 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).

Filipe Gonçalves
  • 20,783
  • 6
  • 53
  • 70
  • I'm using the stock text editor on mac, do you recommend another? – João Miranda Sep 21 '13 at 19:04
  • It's not true that only _one single tab_ is allowed. The rule is that the first character in the line must be a TAB character. After that, you can do whatever you want for the rest of the line (more tabs, spaces, whatever). Whatever is there is passed to the shell to be executed. – MadScientist Sep 21 '13 at 19:22
  • @JoãoMiranda I don't know, never been on a Mac, but I'm sure there are other possibilities – Filipe Gonçalves Sep 21 '13 at 19:30
  • @MadScientist you're right, I edited my answer to be a little more clear. Thanks. – Filipe Gonçalves Sep 21 '13 at 19:31
  • I faced the "missing separator" error when using [conditionals in make](https://www.gnu.org/software/make/manual/html_node/Conditional-Example.html). It seems you would get the error when you forget to add a space between the `ifeq` and the `(` so that it looks like `ifeq (` and not like `ifeq(`. Hope make was a little more clear about this! – kaartic Feb 11 '19 at 06:59
  • I got this error, `warning: NUL character seen; rest of line ignored`, when I had a `makefile` containing a row like: `-include some_object_file.o` (which apparently is WRONG). Once I changed it to `-include some_object_file.o`, the error went away. THANKS! (Here, should of course be replaced by a proper TAB in the text editor. - You will definitely want a text editor which clearly displays whether you have SPACES or a TAB.) – Henke Dec 07 '20 at 16:55
23

can you try running -

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

(after saving a backup of course)

Leeor
  • 19,260
  • 5
  • 56
  • 87
7

It can also be due to a missing colon between .PHONY and your targets

.PHONY all 
all:
<tab><do this>

throws error while below works fine

.PHONY: all 
all:
<tab><do this>
Sravya
  • 661
  • 8
  • 9
4

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.

for example:

target:
    do stuff

will error, but

target:
<tab>do stuff

will not.

Andreas Grapentin
  • 5,499
  • 4
  • 39
  • 57
  • 1
    It's all tabbed, is there another reason for this error? And why does it shows on line 1? – João Miranda Sep 21 '13 at 19:02
  • @JoãoMiranda sometimes, text editors insert spaces, even when you press the tab key. are you **really sure** these are tab characters? Try firing up the simplest possible text editor on your system and have a look if the characters are really tabs. – Andreas Grapentin Sep 21 '13 at 19:06
3

I was writing C++ in vscode and faced the same problem.

The problem was that vscode inserts spaces instead of tabs, your text editor might be doing the same but you didn't notice.

If you are using vscode, add this line to your settings.json file:

// Will control if the editor will insert spaces for tabs. values = <"auto" | true | false>
"editor.insertSpaces": false,

If that didn't work, try opening your Makefile from another text editor e.g(Vim, Notepad, ...), then insert tabs from there, that should insert the tab correctly unless you have the same issue with that text editor too.


Bouns

If you are using vscode you can check if the current character is a space or tab by selecting it, then vscode will represent:

  • tabs:
  • spaces:

Photo that descript how vscode represents spaces and tabs under selection

Mohamed S.Shelf
  • 317
  • 2
  • 8
0

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

0

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.

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:

  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

BrainSlugs83
  • 6,214
  • 7
  • 50
  • 56
0

I just meet the same problem when compliling my source code with auto generated 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.

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