Mail Archives: djgpp/1997/12/19/22:15:24
"David Grant" <dgrant3 AT ibm DOT net> writes:
> Now I want to split this into three files, one which has my class
> definition, the function headers/prototypes called set.h; another, which
> implements these functions, called set.* (what should I call this file?),
> and another file which included the driver code, calls to the functions,
> etc... called main.* (what should I call this file?)
Here is the example:
============================== set.h
class X {
X (void);
// other declarations
};
============================== set.cc
#include "set.h"
X::X (void) {
// do something
}
// other definitions
============================== program.cc
#include "set.h"
int main (void) {
X x;
return 0;
}
============================== compilation line
gcc -g -Wall program.cc set.cc -o program -lgpp
============================== end of example
However, writing this compilation line again and again would be
(1) rather boring, (2) it enforces recompilation of both files,
even if only one changed.
So, you should consider writing simple makefile:
============================== makefile
CXXFLAGS = -g -Wall
LDLIBS = -lgpp
program: program.o set.o
program.o: program.cc set.h
set.o: set.cc set.h
============================== end of makefile
and then simply say `make' to recompile only needed part of your
project.
Hope this helps,
--
Jerzy Witkowski <Jerzy DOT Witkowski AT ii DOT uni DOT wroc DOT pl> o o
University of Wroclaw, Institute of Computer Science /| | |/|
Przesmyckiego 20, PL-51151 Wroclaw |/| | |
room: 11, phone: 0048 71 3247360 /| |/^\| |
phone/fax office secretary: 0048 71 3251271 <__|
- Raw text -