我正在尝试编译一些第三方代码并且遇到了一些奇怪的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说'$&lt;'当它事先将cholmod_aat.c列为依赖项时,它是“未定义的”吗?更令人困惑的是,如果我更换$&lt;用$?在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
发生了什么事?
答案 0 :(得分:3)
答案在MSDN:
$&LT; - 具有比当前目标更晚的时间戳的从属文件。 仅在推理规则中的命令中有效。
它不在“推理规则”中,它位于“描述块”中,因为这些内容在NMAKE中被调用。
--- 编辑:扩展我的原始答案---
术语有点奇怪,因此在这种情况下,最简单的例子就是显示。我创建了一个包含2个规则的makefile - 描述块(a.k.a.目标规则)和推理规则。
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和$&lt;之间的区别。 MSDN文档相当简洁,但代码确实可以正常工作。诚实!
答案 1 :(得分:1)
您可以尝试以下方法:
cholmod_aat.obj: ../Core/cholmod_aat.c
$(C) -c $(I) %s -Fo$@
符号%s映射到列表中的第一个依赖项