[Top][All Lists]

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

Re: CFLAGS dissappear during creation of objects

From: Brian Dessent
Subject: Re: CFLAGS dissappear during creation of objects
Date: Wed, 09 Apr 2008 06:01:18 -0700

address@hidden wrote:

> %.o : %.cpp %.h
>         $(CC) -c $(CFLAGS) $< -o $@
> all: $(OBJECTS)
>         $(CC)   -o processor $(CFLAGS) $(LIB) $(OBJECTS)
> as i do a make i get this:
> g++ -c -g -Wall AudioRecorder.cpp -o AudioRecorder.o
> g++    -c -o dmain.o dmain.cpp                                              
> // -g -Wall dissappeared ??
> g++    -c -o processor.o processor.cpp                                     // 
> -g -Wall dissappeared ??
> g++   -o processor -g -Wall -lccrtp1 AudioRecorder.o dmain.o processor.o

By any chance, is it the case that you have a file AudioRecorder.h but
no dmain.h nor processor.h?  If so, that is why.

In other words, when you write "%.o : %.cpp %.h", the rule can only
apply if all prerequisites exist or can be made.  If %.cpp exists but
%.h does not, this rule won't match and instead an implicit rule from
the built-in database will match.  This explains also why CFLAGS isn't
used -- the built-in rules use the convention of CXXFLAGS when compiling
C++ files and CFLAGS when compiling C files.  See the manual for

Those built-in rules are there to help you, not something you have to
work around.  They are meant to avoid you having to give the boring
compile/link recipies in every Makefile.  Using them you should be able
to write your Makefile as just:

sources := $(wildcard *.cpp)

processor: $(sources:.cpp=.o)
        $(LINK.cpp) $^ $(LDLIBS) -o $@

AudioRecorder.cpp: AudioRecorder.h


reply via email to

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