Reputation: 47
I have a make file called hello.
hello:
cl hello.c
is the contents of it. I Don't have an existing .exe ready, and when I type nmake hello, I get a message that 'hello' is up to date.
Output expecting:
What is the reason I'm not getting the expected output? and how do I get it working?
many thanks.
Upvotes: 0
Views: 318
Reputation: 17438
In your MAKEFILE:
hello:
cl hello.c
The rule to build the hello
target has no explicit dependencies and does not match any inference rules (see below). NMAKE will treat it as a pseudotarget. Because it is both a pseudotarget and has no dependents, it is always considered up-to-date, so the command block cl hello.c
will not be run.
In this case, for building a .exe file from a single .c file, you do not need an explicit rule, you can use NMAKE's built-in .c.exe
inference rule (an inference rule is a special rule of the form .from.to where from and to are filename extensions):
# (You do not need to add this to your MAKEFILE. It is a built-in rule of NMAKE.)
.c.exe:
$(CC) $(CFLAGS) $<
The CC
macro is predefined as cl
and the CFLAGS
macro is not predefined, so is empty. $<
is a special filename macro that expands to a dependent file with a later timestamp than the target. ($<
is only valid when used in an inference rule.)
Try the following MAKEFILE:
hello.exe:
Here, hello.exe
is the first target in the MAKEFILE, and so is the default target that will be built.
The MAKEFILE's rule for the target hello.exe
contains no command block, but since the hello.c
file exists, it matches NMAKE's built-in .c.exe
inference rule (as described above). When applied to the target hello.exe
, this inference rule makes hello.c
an implicit dependent of the target, and the special macro $<
will expand to this implicit dependent, i.e. $<
will expand to hello.c
. Since $(CFLAGS)
is empty, the inference rule will result in the following command being run when the dependent hello.c
is newer than the target hello.exe
:
cl hello.c
Upvotes: 1
Reputation: 69367
I Don't have an existing
.exe
ready
That's ok, but your target is not called hello.exe
, it's called hello
.
What is most probably happening is that nmake
is telling you that hello
is already up to date because you have an existing hello
file in your folder. Either rename the rule to hello.exe
:
hello.exe:
cl hello.c
Or leave it as is and delete the hello
file.
Upvotes: 2