Writing a static library
- Know how to write and compile .c files into .o files using avr-gcc.
- 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:
- The library name (libxxx.a) must start with lib.
- To link against the library, use the linker's (avr-ld) -L option to tell which directory has the library.
For example: -L mylibdir
- Use -lxxx (that's a lowercase ell) to specify which library to use.
- 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>