Reputation: 27
I am writing a makefile in which everything works if I type it into git bash, but when trying to use the command through make, it wont work.
Makefile
CC ?= gcc
CFLAGS ?= -Wall
INCLUDE_DIR ?= src/headers
TARGET_EXEC ?= o.exe
SRC_DIR ?= src
BIN_DIR ?= bin
SRCS := $(wildcard $(SRC_DIR)/*.c)
OBJS := $(addprefix $(BIN_DIR)/, $(notdir $(SRCS:%.c=%.o)))
.PHONY: all
all: $(OBJS)
$(CC) $(OBJS) -o $(BIN_DIR)/$(TARGET_EXEC)
$(BIN_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@ -I$(INCLUDE_DIR)
Console output
process_begin: CreateProcess(NULL, cc -Wall -c src/main.c -o bin/main.o -Isrc/headers, ...) failed.
make (e=2): The system cannot find the file specified.
makefile:17: recipe for target 'bin/main.o' failed
mingw32-make: *** [bin/main.o] Error 2
I have already tried reinstalling git, vscode, mingw. I have also tried removing enviroment variables.
I also stumbled onto this answer: Makefile error make (e=2): The system cannot find the file specified Which also did not work for me.
I have also checked which shell is being used by typing echo $(SHELL)
, which outputs sh.exe
Upvotes: 0
Views: 278
Reputation: 27
Thanks to @Barmar and @teapos418, I found the answer.
The file not found was indeed CC, because the variable $(CC) was declared by using CC ?= gcc
, wich is not the right use case. Changing it to CC = gcc
fixed the problem.
makefile manual: https://www.gnu.org/software/make/manual/html_node/Setting.html
Upvotes: 1