Windows makefile:生成调试信息

时间:2014-05-22 08:05:00

标签: c windows makefile nmake

我必须在Windows上自动化几个简单的构建。 如果我使用特定目标,我可以生成调试信息。

我的Makefile

 .c.obj:
   @echo executing compile rule
   $(cc) $(cdebug) $(cflags) $(cvars) $*.c

 .obj.exe:
   @echo executing linker rule
   $(link) $(ldebug) $(conflags) -out:$@ $** $(conlibs)

 foo.exe: foo.obj
   @echo executing target rule
   $(link) $(ldebug) $(conflags) -out:$@ $** $(conlibs)

nmake /f Makefile.win foo.exe:输出:

Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

executing compile rule
        cl -Zi -Od -DDEBUG -c -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -nologo -GS -D_X
86_=1  -DWIN32 -D_WIN32 -W3 -D_WINNT -D_WIN32_WINNT=0x0500 -DNTDDI_VERSION=0x050
00000 -D_WIN32_IE=0x0500 -DWINVER=0x0500  -D_MT -MTd foo.c
foo.c
executing target rule
        link /DEBUG /DEBUGTYPE:cv  /INCREMENTAL:NO /NOLOGO -subsystem:console,5.
0 -out:foo.exe foo.obj kernel32.lib  ws2_32.lib mswsock.lib advapi32.lib

nmake /f Makefile.win bar.exe:输出:

Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl  bar.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

bar.c
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:bar.exe
bar.obj

请注意,第二次没有执行任何后缀规则。我究竟做错了什么? 我在顶部添加了.SUFFIXES: .exe .obj

2 个答案:

答案 0 :(得分:0)

首先确保.obj.exe都在后缀列表中,否则这些后缀规则将不会生效:

.SUFFIXES: .obj .exe

其次,使用$**非常奇怪。为什么要在链接中添加foo*?我认为你想要$^之类的东西。

除此之外,我可以建议您检查两种情况下由make打印的实际链接线,并找出它们之间的区别。你没有在这里显示。

答案 1 :(得分:0)

GNU make采用一次建模整个依赖关系树的方法,并将修改后的文件一直跟踪到输出。如果make是您使用的唯一构建工具,那么这很棒。如果您有非常大的项目,这不能很好地工作,因此您需要按特定顺序制作它们。如果'make'不支持构建过程的某些工具,那么这不会很好,所以无论如何你都需要多次运行make。

nmake.exe采用最简单的方法:一次只进行一次传递。它假设它将成为更大工具链的一部分。因此,如果您有多遍依赖关系,则需要多次传递nmake。如果您的构建过程需要超过3次,那么您可能正在做一件坏事,您应该修复您的过程。如果您需要多次通过,请大声哭泣,只需编写一个脚本即可完成。

从这里: nmake inference rules limited to depth of 1