[Top][All Lists]

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

Re: a problem with GNU make

From: a R T u n
Subject: Re: a problem with GNU make
Date: 14 Sep 2005 23:45:48 -0700
User-agent: G2/0.2

Paul D. Smith wrote:

> I should point out that the version of GNU make that comes with the
> Cygwin toolkit has been modified by the Cygwin folks: it's not the same
> as the version that comes from the FSF.

That is interesting because in Cygwin it shows that GNU Make is
copyrighted to FSF.

>   artun> The makefile that I am using for this is:
>   artun> %.obj : %.cpp
>   artun>      @$(CC) $(CFLAGS) $<
> The above pattern is not correct for what you want to do.  If you're
> trying to compile $(OBJ_DIR)/foo.obj from $(SRC_DIR)/foo.cpp, your
> target pattern needs to be:
>     $(OBJ_DIR)/%.obj : $(SRC_DIR)/%.cpp
> You will probably find the doc on "How Not to use VPATH" on my web site
> (in my sig) interesting reading.

I've read that doc and learned not to use VPATH for the output. But I
changed the erroneous pattern rule to be:

$(OBJ_DIR)/%.obj : %.cpp
        @$(CC) $(CFLAGS) $<

giving vpath right after directory definitions as:

vpath %.cpp $(SRC_DIR)

As I pasted here I preferred "vpath directive" instead of "VPATH
variable". The reason was that I wanted Make to grab only cpp files. It
was as written in the O'reilly book named GNU Make. I thought it is
true since it compiled with no error. I mentioned it to discuss the

>   artun> $(OUTFILE) : $(OBJ_DIR)$(OBJECTS)
> That won't work; if OBJECTS contains more than one value OBJ_DIR will
> apply only to the first one.  You mean something like:
>     $(OUTFILE) : $(addprefix $(OBJ_DIR)/,$(OBJECTS))
>   artun> But this time I got an error from GNU make that "No rule to
>   artun> make target firstfile.obj".

Your offer worked exactly with no error expect a problem. Let me first
paste my modification:

$(OUTFILE) : $(addprefix $(OBJ_DIR)/,$(OBJECTS))
        @$(LD) $(LFLAGS) $^

I needed to change $< to $^, to let Make to link all the object files,
because when I wrote $< only the first obj file was linked although
there came no error. I guess of course only the first obj file is
linked, because the output file was exactly 2KB although it should have
been hundreds of KBs.

Thanks in helpful advices...

reply via email to

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