Alin Valentin
Alin Valentin

Reputation: 547

Compiling multiple files using CL

How would this GNU makefile look for windows (I must use nmake and CL):

CC = gcc
CFLAGS = -Wall -Wextra -g

build: main

main: utils.o bucket.o hashset.o main.o

utils.o: utils.c utils.h

bucket.o: bucket.c bucket.h

hashset.o: hashset.c hashset.h

main.o: main.c

.PHONY:
clean:
    rm -f *.o *~ main

All I could come up with was this:

CPP = cl
CFLAGS   = /nologo /W4 /EHsc /Za

build : main

main: utils.obj bucket.obj hashset.obj main.obj
    $(CPP) $(CFLAGS) /Fe$@ $**

utils.obj: utils.c
    $(CPP) $(CFLAGS) /Fo$@ $**

bucket.obj: bucket.c
    $(CPP) $(CFLAGS) /Fo$@ $**

hashset.obj: hashset.c
    $(CPP) $(CFLAGS) /Fo$@ $**

main.obj: main.c
    $(CPP) $(CFLAGS) /Fo$@ $**

clean:
    del *.obj main

Note that my homework was implementing a hashset, which I have done, it's just the makefile that troubles me for now. I keep getting errors for every file: unexpected end of file

Upvotes: 2

Views: 4540

Answers (2)

Alin Valentin
Alin Valentin

Reputation: 547

Thanks for helping, in the meanwhile I figured out the answer myself:

CPP = cl
OBJ_LIST = main.obj utils.obj bucket.obj hashset.obj

build: main

main: $(OBJ_LIST)
    $(CPP) /Fe$@ $**

clean:
    del *.obj main.exe

Upvotes: 1

user58697
user58697

Reputation: 7923

C1004 is a compiler error. Try to localize which particular compiler invocation causes it. In any case, $** doesn't look right. Instead, for the .obj rules use $<, and $^ for a link rule.

Upvotes: 0

Related Questions