Guide to compiling with C Interfaces and Implementations (CII)
C Interfaces and
a library of data structures and algorithms for C programmers.
It has been installed in the COMP 40 class directory, and there is a
configuration file for pkg-config.
If you are not familiary with the wonderful pkg-config
program, it provides flags to use on the command line with your C compiler:
- pkg-config --cflags cii40
will produce the flags you need to compile C programs that
interfaces from CII.
- pkg-config --libs cii40
will produce arguments to gcc that link against the CII
Example use: compile a C file to relocatable object code
To take a compilation unit myprog.c, which uses the CII
#include, and compile it into a
relocatable object file myprog.o:
gcc -O -ansi -pedantic -Wall -Werror -c `pkg-config --cflags cii40` myprog.c
Let's break down the options:
Example use: combine relocatable object files into an executable program
Let's suppose we have a simple program consisting only of
myprog.c and the Hanson CII libraries.
To get an executable binary called myprog, we can do this:
gcc -O -ansi -pedantic -Wall -Werror -o myprog myprog.o `pkg-config --libs cii40`
Here are the new options:
If your program has multiple modules, you might include all the
.o files on one command line, as in
- -o myprog says
to produce an executable binary (not a relocatable object file)
`pkg-config --libs cii40` produces command-line options that
can include any functions you need from the cii library.
Due to quirks of the way object files are combined to make programs,
the libraries must come at the end
gcc -ansi -pedantic -Wall -Werror -o unblackedges unblackedges.o bit2.o pnmrdr.o `pkg-config --libs cii40`