help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Makefile macros not working


From: John Graham-Cumming
Subject: Re: Makefile macros not working
Date: Wed, 27 Jun 2007 09:24:06 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040208 Thunderbird/0.5 Mnenhy/0.6.0.104

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

address@hidden wrote:
> I'm trying to use macros in this simple project:
>  
> .cpp.obj:     
> 
>     g++ $? -o $@
> 
>  
> Battle: Battle.obj
> 
>     g++ $? -o $@
> 
>  
> all: Battle
> 
> But the response of make is :
> make: *** No rule to make target `Battle.obj', needed by `Battle'.  Stop.

Here are a few pointers:

1. It would be better if you didn't have blank lines between the targets
and the commands.  So start by writing the Makefile:

.cpp.obj:
     g++ $? -o $@


Battle: Battle.obj
     g++ $? -o $@


2. It's probably better to use $< (the name of the first prerequisite)
instead of $? (which is the list of all prerequisites that are newer
than the target).  So the Makefile becomes:

.cpp.obj:
     g++ $< -o $@


Battle: Battle.obj
     g++ $< -o $@

3. When you write .cpp.obj you are writing an 'old style' suffix rule.
GNU Make won't actually do anything with this rule unless you add the
suffixes .cpp and .obj to the list of suffixes it knows about.  You do
that by adding to .SUFFIXES.

.SUFFIXES: .cpp .obj

.cpp.obj:
     g++ $< -o $@


Battle: Battle.obj
     g++ $< -o $@

4. The error you are getting could occur because Battle.cpp is missing.
 Make sure that it exists and is present in the current directory.

John.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGghCWLphrp73n/hARAk7XAJ4jG9w0Aa/L6NAFLCqBKotg1QwlWwCgmxT2
v9gtuimMhKAoDHmufFbitTI=
=0L70
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]