help-make
[Top][All Lists]
Advanced

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

AW: Re: CFLAGS dissappear during creation of objects


From: j.s.bach
Subject: AW: Re: CFLAGS dissappear during creation of objects
Date: Wed, 9 Apr 2008 16:16:46 +0200 (CEST)

Hello Paul,

Thank you for detailed answer. Followed your recommendation : deleted %.h and 
substituted
CFLAGS with CXXFLAGS. It works.

Cheers,


-----Ursprüngliche Nachricht-----
Datum: Wed, 09 Apr 2008 08:18h
Von: Paul Smith <address@hidden>
An: address@hidden
Kopie: address@hidden
Betreff: Re: CFLAGS dissappear during creation of objects


On Wed, 2008-04-09 at 13:40 +0200, address@hidden wrote:
> I have observed a strange behaviour of make as i tried to create
> objects from 3 source files and bind them together to an executable.
> My in-Makefile-defined CFLAGS variable dissappear 
> after the creation of first object. Here is  my Makefile:

They didn't disappear.

> CC=g++
> NAME=processor
> CFLAGS=-g -Wall
> LIB=-lccrtp1
> OBJECTS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))
> 
> %.o : %.cpp %.h
>         $(CC) -c $(CFLAGS) $< -o $@

This rule tells make "if you have xyz.cpp AND xyz.h, you can use this
recipe containing CFLAGS to build xyz.o".

So presumably when you build AudioRecorder.o, you do have both
AudioRecorder.cpp and AudioRecorder.h and so make uses your rule.

When you build dmain.o and processor.o, you don't have both dmain.cpp
and dmain.h and processor.cpp and processor.h respectively, and so make
cannot use your rule because it doesn't match.  Instead, make uses the
default rule that it has built-in that knows how to build a .o from
a .cpp.

However, THAT rule doesn't use CFLAGS, because CFLAGS is a variable that
is supposed to contain compiler flags specific to C compilers.  Make's
internal rules use CXXFLAGS to hold flags that are specific to C++
compilers, so when make runs its own internal rule to compile a C++ file
like dmain.cpp into dmain.o, it uses CXXFLAGS not CFLAGS.


So, you have a number of problems.  First, your pattern rule should NOT
contain "%.h", unless you are committed to always having a foo.h file
for every single foo.cpp file.

Second, you should be using the de facto standards for variable naming,
which means that since you're compiling C++ files you should be using
CXXFLAGS not CFLAGS.  If you check the GNU make manual you'll find a
list of the commonly used built-in rules and variables.  Use those.

If you do that you can actually remove your pattern rule entirely and
depend on make's built-in rules instead.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.us
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist








reply via email to

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