2

using UBUNTU 20.4 and compiler version gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0,

Im very new to vscode- I built a program in C, getting in its main arguments two strings (as file names)

so I built this Makefile to save myself time during checking my code compiling and running, and wrote it like this:

all: //tried with and without "all:" line//
gcc main.c
./a.out ex1.bin ex2.bin
rm -i a.out

and for some reason after execute make I get this denied in the Terminal and getting this:

Makefile:2: *** missing separator. Stop.

what did I do wrong and how do I fix it?

thanks for the helpers

chqrlie
  • 131,814
  • 10
  • 121
  • 189
N.Av
  • 21
  • 1
  • 6

3 Answers3

8

if Andrea Baldini's answer doesn't work, look to the left of this setting enter image description here . You may find text that says "Spaces: 4" click this and in the drop down menu select "indent using Tabs" and then select 4 or any other value. This solution worked for me.

tiff
  • 139
  • 1
  • 11
1

Have a look to Make rules syntax:

The recipe lines start with a tab character (or the first character in the value of the .RECIPEPREFIX variable; see Special Variables). The first recipe line may appear on the line after the prerequisites, with a tab character, or may appear on the same line, with a semicolon. Either way, the effect is the same. There are other differences in the syntax of recipes. See Writing Recipes in Rules.

You have to start the commands under target all using a TAB character, so ensure your editor is not adding spaces:

all:
    gcc main.c
    ./a.out ex1.bin ex2.bin
    rm -i a.out

Since you are using VS Code you can select Makefile language mode on the bottom right corner to be sure that each time you press TAB key it'll be a real TAB instead of spaces.

enter image description here

Andrea Baldini
  • 1,027
  • 1
  • 6
  • 17
  • now i got ```Makefile:2: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.``` – N.Av May 27 '20 at 20:50
  • Yes indeed TAB, not spaces... What a dreadful design decision. I remember meeting [Stu Feldman](https://en.wikipedia.org/wiki/Stuart_Feldman) at Bell Labs some 35 years ago: the first thing he told me after being introduced as *the make guy* was an apology, *Hi, pleased to meet you, sorry about the TABs...* – chqrlie May 27 '20 at 20:58
  • 1
    @chqrlie even the best can make mistakes :-P – Andrea Baldini May 27 '20 at 21:00
  • @chqrlie I just cant get it to work, tried all sorts of different ways to write it... dont know why its just keeps prompt this denied message... even went here to see tutorial https://makefiletutorial.com/ copied it exactly and its the same – N.Av May 27 '20 at 21:04
  • @נדב אברהם: make sure the file named `Makefile` contains the 4 lines above, the last 3 must start with a TAB character. Open a terminal window and type `make` at the shell prompt in the directory containing the `main.c` file and the argument files. – chqrlie May 27 '20 at 21:07
  • 1
    @נדבאברהם I've edited the answer, since you are using VSCODE select Makefile as language type, then remove all spaces before each command, then press TAB key – Andrea Baldini May 27 '20 at 21:09
  • @chqrlie for some wired reason managed to get it to worked, found some old photo of my cs professor... I changed line 3 to look like that ./"a.out" ex1.bin ex2.bin and it worked.... any idea why? – N.Av May 27 '20 at 21:13
  • added the " " around the .out file – N.Av May 27 '20 at 21:13
  • adding quotation marks to the name of the executable has nothing to do with `missing separator` error, if it works you have fixed the TAB character on each line – Andrea Baldini May 27 '20 at 21:27
  • works with it doesn't work without it... don`t have any way to understand! haha – N.Av May 27 '20 at 21:45
0

If you created a Makefile manually, in a Node.js based project with Docker and docker-compose in order to run more quickly some commands with docker-compose, you have to click on the bottom tab entitled spaces and then click on Convert indentation to tabs selection option.

Below a more visual explanation

Fix Makefile indentation issue

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 11 '22 at 02:10