【问题标题】:Compiling multiple files using CL使用 CL 编译多个文件
【发布时间】:2015-03-13 21:02:23
【问题描述】:

这个 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。 我不断收到每个文件的错误:文件意外结束

【问题讨论】:

  • 错误说明了什么? (错误,整个错误,只有错误)
  • 致命错误 C1004:发现意外的文件结尾 NMAKE:致命错误 U1077:'"F:\Program Files\Microsoft Visual Studio 12.0 Ultimate 2013\VC\BIN\cl.EXE"':返回码“0x2”停止。
  • 您是否尝试在 Makefile 的最后一行之后按 Enter 键?
  • 在 makefile 末尾换行没有帮助
  • 我也收到此警告:F:\Program Files\Microsoft Visual Studio 12.0 Ultimate 2013\VC\INCLUDE\sal.h(156) : 警告 C4001: nonstandard extension 'single line comment' was used

标签: c windows makefile nmake cl


【解决方案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

【讨论】:

  • 应该是main.exe,无论 main 是什么。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    • 2019-08-02
    • 1970-01-01
    • 2019-09-22
    • 2011-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多