Home > Blockchain >  Makefile giving error with No target for rule G
Makefile giving error with No target for rule G

Time:01-02

Complete Makefile noob here. I cannot figure out why this is happening, but I think it is whitespace/tab. I have this Makefile:

BUILD_DIR = build/debug
CC = g  
SRC_FILES = $(wildcard $(SRC_DIR)/*.cpp)
OBJ_NAME = play
INCLUDE_PATHS = -Iinclude
LIBRARY_PATHS = -Llib
COMPILER_FLAGS = -std=c  11 -Wall -O0 -g
LINKER_FLAGS = -lsdl2

all: $(CC) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(SRC_FILES) -o $(BUILD_DIR)/$(OBJ_NAME)

and it gives this error: make: *** No rule to make target `g ', needed by `all'. Stop.

If I move the string to the bottom with tab and just use all: on one line and the string on the other it gives this:

Makefile:12: *** missing separator. Stop.

And I thought Python was crazy about space. Cannot figure out what I am doing wrong.

CodePudding user response:

You need to put commands on a new line:

all:
    $(CC) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(SRC_FILES) -o $(BUILD_DIR)/$(OBJ_NAME)

and make sure it is indented with tab, not space

It is also not python, it's make

You couuld also use a semicolon to separate dependencies from commands like this:

all: $(SRC_FILES); $(CC) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(SRC_FILES) -o $(BUILD_DIR)/$(OBJ_NAME)
  • Related