GP142 for XWindows

Although support for GP142 under XWindows gets the least amount of support, it actually works pretty well. There are a few things you need to know.

  1. You must remember to change the #define constant at the top of gp142.h to X11R6.
  2. After that, the hard is finding the X11 system files needed to compile.  There are two kinds of files you need: files to be #include'd (e.g., <X11/Xlib.h>) and libray files of X routines to link with.  Here is a table showing were we found these on randomly chosen Linux and FreeBSD systems available to us:
    Linux FreeBSD
    #include (.h) files /usr/X11R6/include/X11 /usr/X11R6/include
    Libraries /usr/X11R6/lib /usr/X11R6/include
    Sample command line gcc -idirafter /usr/X11R6/include *.c -L/usr/X11R6/lib -lX11 -lc -lm
    gcc -idirafter /usr/X11R6/include *.c -L/usr/X11R6/lib -lX11 -lc -lm

    Your results may vary.  You will get messages like "Unable to open file <Xlib.h>" if the include file directory (the one specified by the -idirafter switch) is wrong.  You will get messages about "undefined reference to..." for various symbols (e.g., XDrawString) if the library directory (the one specified by the -L switch) is wrong.  In either case, you'll have to look around on your system to find the correct directories.

  3. Here is a sample Makefile from Linux 1.2. It builds an executable named pcad from the source file pcad.c (which contains main()) and gp142.c. Make certain that the commands which follow the dependancies are indented with a tab, and not spaces!
        XLIBFILES = /usr/X11R6/lib/libX11.so
    
        pcad: pcad.o gp142.o
            gcc -o pcad pcad.o gp142.o $(XLIBFILES) -lm
    
        pcad.o: pcad.c
            gcc -c pcad.c
    
        gp142.o: gp142.c gp142.h gp142lib.h
            gcc -c gp142.c
    
  4. This is a slightly more complex Makefile from Linux 6.2, which can be used for Hw4 from Spring 2001. It builds an executable named tron from the source file hw4.c (which contains main()), and depends on gp142.c and functions declared in tron.h. tronDraw.c and tronMove.c contain the implementations of the functions declared in tron.h. Make certain that the commands which follow the dependancies are indented with a tab, and not spaces!
        XLIBFILES = /usr/X11R6/lib/libX11.so
    
        # This is the rule which builds the executable.  It depends on
        #   all of the object files, which are created with the rules below
        tron: tronDraw.o tronMove.o hw4.o gp142.o
            gcc -g -Wall -ansi -o tron *.o $(XLIBFILES) -lm
    
        # Note that all the files are compiled with the -g, -Wall,
        # and -ansi flags.
        #   -g ensures that debugging symbols are built into your program
        #    (so you can debug your program with, for example, gdb).
        #   -ansi enforces strict compliance with the ansi-C spec
        #   -Wall is short for "Warnings: all".  If the warnings grow
        #    excessive, you may want to remove this flag
        hw4.o: hw4.c tron.h
            gcc -g -Wall -ansi -c hw4.c
    
        tronDraw.o: tronDraw.c tron.h
            gcc -g -Wall -ansi -c tronDraw.c
    
        tronMove.o: tronMove.c tron.h
            gcc -g -Wall -ansi -c tronMove.c
    
        gp142.o: gp142.c gp142.h gp142lib.h
            gcc -g -ansi -c gp142.c