0
votes

I have a make file:

# Makefile
CC = gcc
SRC = pixel.c
TARGET = pixel.exe
OBJECTS = bmp.o pixel.o
#CFLAGS_W = -Wall -Wl,-subsystem,windows
CFLAGS_W = -Wall
LFLAGS_W = -lSDL2
INCS_W = -I.\SDL2\include
LIBS_W = -L.\SDL2\lib\x64

all: $(TARGET)

$(TARGET): $(OBJECTS)
    $(CC) $(INCS_W) $(LIBS_W) $(CFLAGS_W) $(LFLAGS_W) -g -o $(TARGET) $(OBJECTS)

it will build bmp.c, but when it tries to build pixel.c I get the error:

pixel.c:6:10: fatal error: SDL.h: No such file or directory

however, pixel.c has been building fine all the time I was just building it on its own (before I added bmp.c), using the command:

all:
    $(CC) $(SRC) $(INCS_W) $(LIBS_W) $(CFLAGS_W) $(LFLAGS_W) -g -o $(TARGET)

I really struggle with makefiles because I just don't use them enough, but this doesn't really feel like a "make" problem.

I'm using mingw32-make and gcc in a windows sandbox.

EDIT:

I have added

.c.o:
    $(CC) $(INCS_W) $(LIBS_W) $(CFLAGS_W) $(LFLAGS_W) -g -c $< -o $@

to my makefile, which gets me a step further (I think), but now complains that all of the SDL functions are undefined

C:\Users\WDAGUtilityAccount\Desktop\Projects\Pixel>mingw32-make
gcc -I./SDL2/include -L./SDL2/lib/x64 -Wall -lSDL2 -g -c bmp.c -o bmp.o
gcc -I./SDL2/include -L./SDL2/lib/x64 -Wall -lSDL2 -g -c pixel.c -o pixel.o
gcc -I./SDL2/include -L./SDL2/lib/x64 -Wall -lSDL2 -g -o pixel.exe bmp.o pixel.o
pixel.o: In function `main':
C:\Users\WDAGUtilityAccount\Desktop\Projects\Pixel/pixel.c:119: undefined reference to `SDL_Init'
C:\Users\WDAGUtilityAccount\Desktop\Projects\Pixel/pixel.c:121: undefined reference to `SDL_GetError'
C:\Users\WDAGUtilityAccount\Desktop\Projects\Pixel/pixel.c:126: undefined reference to `SDL_CreateWindow'
C:\Users\WDAGUtilityAccount\Desktop\Projects\Pixel/pixel.c:131: undefined reference to `SDL_GetError'
...

I can get the whole project to compile if I just do this on its own:

SRC = bmp.c pixel.c
...
test:
    $(CC) $(SRC) $(INCS_W) $(LIBS_W) $(CFLAGS_W) $(LFLAGS_W) -g -o $(TARGET)

which is fine, it'll do, but it rebuilds everything every time, and I'd like to know why it isn't working anyway :)

You should use forward-slashes in pathnames when dealing with make, or with other POSIX-derived programs like POSIX shell and GCC. - MadScientist
@MadScientist sure, although I'm running make from a regular cmd.exe window, and get lovely errors like C:\Users\WDAGUtilityAccount\Desktop\Projects\Pixel/pixel.c:119: undefined reference to SDL_Init so I don't think windows 10 really cares about slash direction these days ;) - MalphasWats
Windows doesn't. But POSIX tools, like the POSIX shell (and make, depending on how it was compiled) etc. definitely do care. That's why it's best to use forward slashes since they work in both environments (except for some cmd.exe built-ins like dir etc.) while backward-slashes only work with Windows tools. - MadScientist
Anyway, that error you're showing means now the compiler can find the header file, which is what you wanted. If the code still doesn't compile that's a different issue. - MadScientist
@MadScientist Yeah, I've been playing with it to try and work out why it's not working right. I can get it to the next step by adding another rule to the file, but it's still not compiling - well, looks like it's not linking properly. I'm not 100% sure. - MalphasWats