C functions, integration

The steps necessary to integrate a user C program with the D3 run-time library are:

  • Build a branch table (which may be empty) for any functions that will be called by FlashBASIC subroutines calling percent function calls.

  • Edit and compile the user C programs.

  • Link the application with the D3 run-time library.

The following describes the necessary procedures to create the cdemo example application shipped with the D3 package.

To create the example application:

  1. In UNIX, copy Makefile and cdemo.c to the current directory.

    Go to your UNIX user’s home directory and copy Makefile and cdemo.c from /usr/lib/pick.

  2. Log in to D3 and type addbi with no arguments.

    The addbi command builds a dummy branch table for use by the BASIC-C interface. This branch table is not directly used by the C to D3 interface, but is required to properly link the D3 run-time library. This step creates two modules called px.user.o and libgmu.a. These modules need only to be created once.

  3. Edit the C program source code and Makefile.

    For the cdemo program, the source code is already complete. If this were a new program, the user would change the desired source file or files, and modify Makefile to integrate those files into the final link.

  4. Link the application using make.

    In UNIX, type make cdemo. This compiles the cdemo.c source into an object and links this with the D3 run-time library to create a UNIX application.

  5. Run the application.

    When the make completes, an application called cdemo will exist on the current directory. This application is similar to the UNIX cat program, except that cdemo outputs the raw contents of a D3 file and item. For instance, to view the color program in dm,bp, type:

    ./cdemo bp color
    

    Debugging can be done with the usual UNIX debuggers such as sdb or dbx.