next up previous contents
Next: Libraries Up: Compiling Previous: Compiler Options   Contents

Example: Compiling Zoo Classes

We are going to develop a C++ Zoo program. If you are unfamiliar with C++ then don't worry about the code details; the principles we will demonstrate apply equally well to C and Fortran. The Zoo program starts with an Abstract class Animal from which 3 specific animals: Dog, Pig and Human are derived. The main Zoo program creates one of each type and then places them in a collection illustrating a simple use of the STL (Standard Template Library). STL is a powerful addition to the C++ language so even this trivial example exploits it.

The code is can be found at:-

  ~west/ttp/manual/unix_programming/cpp

and if you want to follow along with this example:-

  mkdir <some_scratch_directory>
  cd <some_scratch_directory>
  cp  ~west/ttp/manual/unix_programming/cpp/* ./

To compile the code:-

g++ -c Animal.cpp
g++ -c Dog.cpp
g++ -c Human.cpp
g++ -c Pig.cpp
g++ -c Zoo.cc

or, more simply, as the compiler can take multiple input files:-

g++ -c Animal.cpp Dog.cpp Human.cpp Pig.cpp Zoo.cc



P.D. Gronbech (IT Staff) 2015-10-02