0

I have developing an application in C for a raspberry pi. Until now I was cross-compiling this application in Eclipse and debugging in a raspberry. Now I have all the code working I want to create a make file to compile it all in my raspberry.

I have 2 folders (src and inc) where I keep all the code.

I have tried something like this:

CC          = gcc
LD          = gcc 
CFLAG       = -Wall
PROG_NAME   = test

SRC_DIR     = ./src
BUILD_DIR   = ./build
BIN_DIR     = ./bin
SRC_LIST = $(wildcard $(SRC_DIR)/*.c)
OBJ_LIST = $(BUILD_DIR)/$(notdir $(SRC_LIST:.c=.o))

.PHONY: all clean $(PROG_NAME) compile

all: $(PROG_NAME)

compile: 
    $(CC) -c $(CFLAG) $(SRC_LIST) -o $(OBJ_LIST) -lwiringPi -lpaho-mqtt3c

$(PROG_NAME): compile
    $(LD) $(OBJ_LIST) -o $(BIN_DIR)/$@

clean:
   rm -f $(BIN_DIR)/$(PROG_NAME) $(BUILD_DIR)/*.o

But after executing "make" in console, I always get an error:

makefile:17: *** missing separator. Alto.

I do not know where the fail is. This is my first makefile.

All .c files have their .h without paths. something like #include "file.h".

Biribu
  • 535
  • 3
  • 12
  • 27
  • 2
    This is very often caused by using spaces instead of hard tabs within the Makefile. Remove the whitespace before the indented lines, ensure your editor is using hard tabs, and re-insert the indents using the hard tabs. – stevieb Jun 16 '19 at 15:16
  • Thanks. That was exactly what happened. Now I got other errors. but they come due to a bad makefile configuration. I will work on them. – Biribu Jun 16 '19 at 15:28
  • Added as an answer. – stevieb Jun 16 '19 at 15:33

1 Answers1

1

This is very often caused by using spaces in place of hard tabs within the Makefile on the indented lines. Makefiles are picky that way.

Simply set your editor to use hard tabs in place of 4 (or whatever) space tabs, and then re-tab the file, or in your case, simply open the file with another editor that uses hard tabs (nano for example), delete the leading whitespace, and replace with tabs (as your Makefile is extremely short and basic).

In vim:

:set tabstop=8
:set noet
:%s/^\s\+/\t/g

That will disable the tab conversion to spaces, set the tab width to 8, and then safely replace all the indent spaces to full tabs.

to revert vim back to how it was:

:set tabstop=4
:set et
stevieb
  • 9,065
  • 3
  • 26
  • 36