When applications grow large they are usually broken into multiple smaller, manageable pieces, called compilation units. Each piece is compiled separately and then the pieces are stitched together by the linker to produce the final application.

When you partition a application into separate compilation units you will need to indicate how a symbol defined in one unit is referenced in other units. This section will show you how to declare symbols exported or imported so they can be used in more than one unit.

When building applications, you often find pieces of code which can be reused in other applications. Rather than duplicating source code, you can package these units together into a library which can be reused in different applications.

The CrossWorks tools were designed to be flexible and let you to easily write space-efficient programs using libraries and separate compilation. To that end, the assembler and linker combination provides a number of features which are not found in many compilation systems.

- Optimum-sized branches The linker automatically resizes branches to labels where the label is too far away to be reached by a branch instruction. This is completely transparent to you as a programmer—when you use branch instructions, your linked program will always use the smallest possible branch instruction. This capability is deferred to the linker so that branches across compilation units are still optimised.
- Removing dead code and data The most important features of the linker are its ability to leave all unreferenced code and data out of the final application. The linker automatically discards all code and data fragments in a program that are not reachable from any entry symbols.
- Whole program optimization The linker can optimize the application as a whole, rather than on a per-function or per-compilation-unit basis.