简体   繁体   English

Makefile中的$$ @是什么意思?

[英]What does $$@ mean in a makefile?

I'm porting a makefile from AIX to Linux - it's falling over on this line: 我正在将一个makefile从AIX移植到Linux-它落在了这一行上:

program.o : header1.h header2.h
program : $$@.o lib1.a lib2.a lib3.a

The error is: 错误是:

make: *** No rule to make target `$@.o', needed by `program'.  Stop.

Does anyone recognise this $$@ variable? 有人认识这个$$ @变量吗? I can't find any reference to it anywhere. 我在任何地方都找不到它的参考。

Thanks! 谢谢!

This rule must be in a section marked 此规则必须位于标记为

.SECONDEXPANSION:

The first $ is expanded in the first pass yielding $@.o and then the second pass produces program.o as usual. 第一个$在第一遍扩展为$@.o ,然后第二遍照常生成program.o

This is a GNU make feature. 这是GNU make的功能。 You should ensure that GNU make (rather than some other) is being used on the target and that it's up to date. 您应该确保在目标上使用了GNU make(而不是其他),并且它是最新的。 You can do this with 你可以这样做

make --version

Version 4 is available, but 3.8x ought to be fine. 版本4可用,但3.8x应该可以。

The relevant documentation is here . 相关文档在这里

If your make supports $$@, then $$@ would just evaluate to program on this line of this makefile. 如果您的make支持$$ @,则$$ @会求值以在此makefile的这一行进行编程。

$$@ can be the same as the name of the target on a DEPENDENCY (not command) line. $$ @可以与DEPENDENCY(而非命令)行上的目标名称相同。 In this sense the makefile you have is correct (the $$@ is on a line where it's supposed to be). 从这个意义上说,您拥有的makefile是正确的($$ @应该在应该位于的行上)。 $$@ isn't supported by all make programs. 并非所有make程序都支持$$ @。

According to the "Managing Projects with Make" book I use, $$@ means the same as $@ - the name of the target - but $$@ and $@ are used in different places in a makefile: 根据我使用的“使用Make管理项目”一书,$$ @的含义与$ @-目标名称相同-但是$$ @和$ @在makefile中的不同位置使用:

$@ can only be used on a command line $ @只能在命令行上使用

target : dependency1 dependency2 目标:依赖项1依赖项2

command1 >> $@ command1 >> $ @

$$@ can only be used on a dependency line as in: $$ @只能在依赖项行中使用,如下所示:

docmk : $$@.c 文件:$$ @。c

EVALUATES TO: 评估到:

docmk : docmk.c docmk:docmk.c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM