1

我正在尝试编译一些第三方代码并遇到了一些奇怪的 NMAKE 行为。

Makefile 中的行是

cholmod_aat.o: ../Core/cholmod_aat.c
        $(C) -c $(I) $< -Fo$@

这会产生以下错误:


Wed, Aug 15 2012 23:25:20           ../Include/cholmod.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_blas.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_check.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_cholesky.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_complexity.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_config.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_core.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_internal.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_matrixops.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_modify.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_partition.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_supernodal.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_template.h
Fri, Aug 17 2012 16:06:24           ../Core/cholmod_aat.c
                                  cholmod_aat.o target does not exist
NMAKE : warning U4006: special macro undefined : '$<'
        cl -O2 -nologo -D__MINGW32__ /MD -DNPARTITION -c -I../../AMD/Include -I.
./../AMD/Source -I../../COLAMD/Include  -I../../metis-4.0/Lib -I../../CCOLAMD/In
clude -I../../CAMD/Include  -I../Include -I../../UFconfig  -Focholmod_aat.o
cl : Command line error D8003 : missing source filename
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0
\VC\BIN\cl.EXE"' : return code '0x2'
Stop.

为什么 nmake 事先将 cholmod_aat.c 列为依赖项时说 '$<' 是“未定义的”?更令人困惑的是,如果我将 $< 替换为 $? 在 makefile 中,nmake 扩展 '$?' 正好:


Wed, Aug 15 2012 23:25:20           ../Include/cholmod.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_blas.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_check.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_cholesky.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_complexity.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_config.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_core.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_internal.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_matrixops.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_modify.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_partition.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_supernodal.h
Wed, Aug 15 2012 23:25:20           ../Include/cholmod_template.h
Fri, Aug 17 2012 16:06:24           ../Core/cholmod_aat.c
                                  cholmod_aat.o target does not exist
        cl -O2 -nologo -D_MINGW32_ /MD -DNPARTITION -c -I../../AMD/Include -I.
./../AMD/Source -I../../COLAMD/Include  -I../../metis-4.0/Lib -I../../CCOLAMD/In
clude -I../../CAMD/Include  -I../Include -I../../UFconfig ../Include/cholmod.h .
./Include/cholmod_blas.h ../Include/cholmod_check.h ../Include/cholmod_cholesky.
h ../Include/cholmod_complexity.h ../Include/cholmod_config.h ../Include/cholmod
_core.h ../Include/cholmod_internal.h ../Include/cholmod_matrixops.h ../Include/
cholmod_modify.h ../Include/cholmod_partition.h ../Include/cholmod_supernodal.h
../Include/cholmod_template.h ../Core/cholmod_aat.c -Focholmod_aat.o

到底是怎么回事?

4

2 回答 2

3

答案在MSDN上:

$< - 时间戳晚于当前目标的依赖文件。仅在推理规则中的命令中有效。

它不在“推理规则”中,而是在“描述块”中,因为这些东西在 NMAKE 中被调用。

---编辑:扩展我原来的答案---

术语有点奇怪,所以在这种情况下,最容易通过示例来展示。我创建了一个包含 2 个规则的 makefile - 一个描述块(又名目标规则)和一个推理规则。

C:\temp>type makefile.txt
c.txt : a.txt b.txt
        @echo $?
        @echo %s

.SUFFIXES: .log

.log.txt:
        @echo $<

我为虚拟输入创建了空文件 a.txt、b.txt 和 d.log。然后我在目标 c.txt 和 d.txt 上运行 makefile:

C:\temp>nmake /f makefile.txt c.txt d.txt

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

a.txt b.txt
a.txt
d.log

C:\temp>

希望这能说明 $?、%s 和 $< 之间的区别。MSDN 文档相当简洁,但代码确实按文档说明工作。诚实的!

于 2014-08-28T12:49:35.710 回答
1

您可以尝试以下方法:

cholmod_aat.obj: ../Core/cholmod_aat.c
        $(C) -c $(I) %s -Fo$@

符号 %s 映射到列表中的第一个依赖项

于 2013-02-05T06:05:46.267 回答