0

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

  • If you just type `cc` into a Command Prompt window, does it work? – Barmar Feb 04 '23 at 16:30
  • The file that cannot be found is `cc`, check that cc as a command works and at least one of the directories in `$(PATH)` points to your mingw install directory. – teapot418 Feb 04 '23 at 16:31
  • @teapot418 CC does not work, but my path already points to my mingw directory because the gcc command works. – 1NilusNilus Feb 04 '23 at 16:32
  • 1
    Why is it trying to launch cc anyway? `CC ?= gcc` If you wanted to run gcc, you might want to make this unconditional or clear your CC environment variable. (`?=` is assign only if not already assigned, did you mean `=` ?) – teapot418 Feb 04 '23 at 16:33

1 Answers1

1

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