CS320 - OBJECT-ORIENTED SOFTWARE DEVELOPMENT WITH C++

Handout #4: Using C/C++ on our computers

                        VAX/VMS (FAITH)
                        ------- -------

1. C source files should be created with a .C extension; C++ source files
   should have a .CC extension.   For either language, header files should
   have a .H extension.

2. To compile a source file written in C, use the following command

        GCC filename.C                  - e.g. GCC FOO.C

   For C++, use:

        GCC/PLUS filename.CC            - e.g. GCC/PLUS FOO.CC

   For either language, if a program consists of several source files, each
   must be compiled this way

3. To link a program written in C, use the following command

        LINK filename(s), LIBG/OPT      - e.g. LINK FOO, BAR, BAZ, LIBG/OPT

   For C++ use:

        LINK filename(s), LIBGXX/OPT    - e.g. LINK FOO, BAR, BAZ, LIBGXX/OPT

4. You can also use the EXECUTE command if your program consists of a single
   source file

   - e.g. EXEC FOO.C    (for a program written in C)
     or   EXEC FOO.CC   (for a program written in C++)



                        SGI/IRIX (Workstations)
                        -------- --------------

1. C source files should have a name ending with .c ; C++ source files should
   have name ending with .cc .   For either language, header files should have a
   name ending with  .h .  (On Unix systems, case is important in file names!
   By convention, normal file names are constructed using lowercase letters.)

2. On Unix systems, the same command (in slightly different forms) can be used
   to compile, or link, or both compile and link a program.  Further, several 
   files can be compiled with the same command, and (if linking) source files 
   needing to be compiled and object files resulting from a previous compilation
   can be combined on the same command line.

   a. In all cases, the command used for source files written in C is either:

        cc      - to use the Silicon Graphics C compiler        
      or
        gcc     - to use the GNU C compiler (recommended)

      the command used for source files written in C++ is

        g++     - to use the GNU C++ compiler

   b. To compile a source file or files without linking , the -c option is used
      on the command line 

      Examples:         gcc -c foo.c            Compiles foo.c to produce foo.o

                        g++ -c a.cc b.cc        Compiles a.cc to produce a.o
                                                 and b.cc to produce b.o

   c. To (possibly) compile and link one or more files, the -c option is
      omitted.  Source files (name ending in .c or .cc as the case may be) and 
      object files resulting from a previous compilation (name ending in .o)
      may be mixed.

      Examples:         gcc foo.c               Compiles foo.c to produce foo.o,
                                                 then links foo.o to produce an
                                                 executable

                        g++ a.cc b.cc           Compiles a.cc to produce a.o 
                                                 and b.cc to produce b.o, then
                                                 links them both to produce an
                                                 executable

                        g++ a.cc b.o c.o d.o    Compiles a.cc to produce a.o,
                                                 then links this with previously
                                                 compiled object files b.o, c.o,
                                                 d.o to produce an executable

                        gcc foo.o               Links previously compiled foo.o
                                                 to produce an executable

   d. In all of the cases discussed above, the executable file is named a.out .
      It can be renamed to something else by using the mv command:

        Example:        mv a.out foo            Renames the executable to foo

      (You must do something like this if your are going to have several
       executables around, since they can't all be called a.out !)

   e. You can specify the name for the executable on the command line, thus
      avoiding the renaming step, by using the -o filename option:

        Examples:       g++ -o foo foo.cc       Compiles foo.cc and then links
                                                 it to produce an executable
                                                 called foo

                        g++ -o foo a.o b.o      Links previously compiled files
                                                 a.o, b.o to produce an 
                                                 executable called foo

                        g++ -o foo a.cc b.o c.o Compiles a.cc, then links with
                                                 previously compiled b.o and
                                                 c.o to produce an executable
                                                 called foo