简体   繁体   中英

What does $$@ mean in a makefile?

I'm porting a makefile from AIX to Linux - it's falling over on this line:

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.

This is a GNU make feature. You should ensure that GNU make (rather than some other) is being used on the target and that it's up to date. You can do this with

make --version

Version 4 is available, but 3.8x ought to be fine.

The relevant documentation is here .

If your make supports $$@, then $$@ would just evaluate to program on this line of this makefile.

$$@ can be the same as the name of the target on a DEPENDENCY (not command) line. In this sense the makefile you have is correct (the $$@ is on a line where it's supposed to be). $$@ isn't supported by all make programs.

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:

$@ can only be used on a command line

target : dependency1 dependency2

command1 >> $@

$$@ can only be used on a dependency line as in:

docmk : $$@.c

EVALUATES TO:

docmk : docmk.c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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