Writing a static library

It's simple.

Prerequisite knowlege:
  1. Know how to write and compile .c files into .o files using avr-gcc.
  2. Libraries would not typically contain a main() function.

First, compile your .c files into object files like you usually would.

Then, use the librarian to put them into an archive file:

avr-ar -c -r -s mylibdir/libutils.a obj1.o obj2.o obj3.o

To link against the library, you should know:
  1. The library name (libxxx.a) must start with lib.
  2. To link against the library, use the linker's (avr-ld) -L option to tell which directory has the library.
    For example: -L mylibdir
  3. Use -lxxx (that's a lowercase ell) to specify which library to use.
  4. The linker will automatically put the lib on the front and the .a on the end, so just use -lxxx when linking.
    so, linking against library xxx should have a file called libxxx.a in directory mylibdir.

To link against the library, use the following linker options:

avr-ld -Lmylibdir -lutils <other linker options here>