delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/19/22:15:24

From: Jerzy Witkowski <Jerzy DOT Witkowski AT ii DOT uni DOT wroc DOT pl>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Beginer's Question
Date: 19 Dec 1997 12:13:23 +0100
Organization: University of Wroclaw
Lines: 60
Sender: jwi AT swiatowit
Message-ID: <x6zplxsi0c.fsf@ii.uni.wroc.pl>
References: <34982465 DOT 0 AT news2 DOT ibm DOT net>
NNTP-Posting-Host: swiatowit.ii.uni.wroc.pl
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

"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 -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019