Link Error with MinGW?

Currently trying to get into windows programming with C.
I've written a makefile like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CC = mingw32-gcc
RC = windres
LDFLAGS = -lgdi32 -mwindows
BIN = w0
OBJECTS = w0.o w0res.o

$(BIN): $(OBJECTS)
	$(CC) w0.o w0res.o -o $(BIN) $(LDFLAGS)

w0.o: w0.c w0.h
	$(CC) -c w0.c -Wall

w0res.o: w0.rc w0.h
	$(RC) w0.rc -o w0.o

If I run this with mingw32-make, I get the following error in ld (undefined reference to WinMain@16)

If I build w0 manually, like this:
 
mingw32-gcc w0.c w0res.o -o w0 -lgdi32 -mwindows -s
everything works fine, so I figured I am screwing up with compiling w0.c properly. Can you please help me, I somehow can't figure out what's wrong (before you ask: yes, w0.c DOES have a WinMain function)

And I want to practice doing stuff manually so I get better at grasping what is actually going on, so please do not suggest using an IDE. I have C::B, and I'd normally use that, but in this case I don't want to.
EDIT: Oh, and w0.c contains a WinMain function
1
2
3
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   PSTR szCmdLine, int iCmdShow)


So that's NOT the problem.

EDIT: I think I spotted it, and I think I am stupid now. I compiled w0.rc to w0.o instead of w0res.o and thus overwrited my other w0.o file all the time.
Last edited on
Topic archived. No new replies allowed.