[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Makefile question (g++ compiling)
From: |
Paul Pluzhnikov |
Subject: |
Re: Makefile question (g++ compiling) |
Date: |
Mon, 14 Jan 2008 17:33:12 -0800 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux) |
xz <zhang.xi.cn@gmail.com> writes:
> I understand the most simple (but kinda silly) way to write a Makefile
> is to simply put all related the cpp files after the colon and compile
> them all, like this:
>
> testprogram: A.cpp B.cpp C1.cpp C2.cpp test.cpp
> <Tab>g++ $? -o $@
No, NOT like that!
>From 'info make':
`$?'
The names of all the prerequisites that are newer than the target,
with spaces between them. For prerequisites which are archive
members, only the member named is used (*note Archives::).
This means that if you 'make testprogram', then modify B.cpp, then
'make testprogram' again, only B.cpp will be newer than the target,
and the command that make will execute will be:
g++ B.cpp -o testprogram
which likely will result in unresolved symbols at link time.
> However, the wierd thing that I came across was:
> Every time I run "make testprogram" for the first time, the compiler
> (g++) complaines that it cannot find the definitions of some member
> functions, which I have defined in A.cpp or B.cpp
It complains because of the above, and it *removes* testprogram,
which now makes all of the sources 'newer', so next time you run
make, it rebuilds them all, and the link succeeds.
Here is the *entire* makefile which will correctly rebuild your
program *every* time:
testprogram: A.o B.o C1.o C2.o test.o
$(CXX) -o $@ $^
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.