2

这个 GNU makefile 如何查找 windows(我必须使用 nmake 和 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

我能想到的就是:

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

请注意,我的作业是实现一个哈希集,我已经完成了,这只是现在困扰我的 makefile。我不断收到每个文件的错误:文件意外结束

4

2 回答 2

1

感谢您的帮助,同时我自己想出了答案:

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

build: main

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

clean:
    del *.obj main.exe
于 2015-03-13T22:50:23.350 回答
0

C1004 是编译器错误。尝试本地化导致它的特定编译器调用。无论如何,$**看起来都不对。相反,.obj规则使用$<, 和$^链接规则。

于 2015-03-13T21:51:57.967 回答