On Wed, 2008-04-09 at 13:40 +0200, j.s.bach o2online.de 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 <psmith gnu.org> Find
some GNU make tips at:
http://www.gnu.org
http://make.mad-scientis
t.us
"Please remain calm...I may be mad, but I am a
professional." --Mad Scientist
_______________________________________________
Help-make mailing list
Help-make gnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make
|