Next Previous Contents

4. Building a GEOS sequential application

Before proceeding, please read the compiler, assembler, and linker documentation, and find the appropriate sections about building programs, in general.

GEOS support in cc65 is based on the Convert v2.5 format, well-known in the GEOS world. It means that each file built with the cc65 package has to be deconverted, in GEOS, before it can be run. You can read a step-by-step description of that in the GEOS section of the cc65 Compiler Intro.

Each project consists of four parts, two are provided by cc65. Those parts are:

  1. application header
  2. start-up object
  3. application objects
  4. system library
2. and 4. are with cc65; you have to write the application, yourself. ;-)

The application header is defined in the HEADER section of the .grc file, and processed into an assembly .s file. You must assemble it, with ca65, into the object .o format.

4.1 Building a GEOS application without cl65

Assume that there are three input files: "test.c" (a C source), "test.h" (a header file), and "resource.grc" (with menu and header definitions). Note the fact that I don't recommend naming that file "test.grc", because you will have to be very careful with names (grc will make "test.s" and "test.h" out of "test.grc", by default; and, you don't want that because "test.s" is compiled from "test.c", and "test.h" is something completely different)!

One important thing -- the top of "test.c" looks like:

#include <geos.h>
#include "resource.h"
There are no other includes.

First step -- compiling the resources

$ grc resource.grc
will produce two output files: "resource.h" and "resource.s".

Note that "resource.h" is included at the top of "test.c". So, resource compiling must be the first step.

Second step -- assembling the application header

$ ca65 -t geos resource.s
And, voilá -- "resource.o" is ready.

Third step -- compiling the code

$ cc65 -t geos -O test.c
$ ca65 -t geos test.s
That way, you have a "test.o" object file which contains all of the executable code.

Fourth and last step -- linking it together

$ ld65 -t geos -o test.cvt resource.o geos.o test.o geos.lib
"resource.o" comes first because it contains the header. The next one is "geos.o", a required starter-code file; then, the actual application code in "test.o", and the last is the GEOS system library.

The resulting file "test.cvt" is an executable that's contained in the well-known GEOS Convert format. Note that it's name (test) isn't important; the real name, after deconverting, is the DOS name that was given in the header definition.

At each step, a -t geos was present on the command-line. That switch is required for the correct process of GEOS sequential app. building.

Next Previous Contents