Embedded C program libraries and linking

What is a compilation of programs? Maybe it is more or less clear? But what is program linking? I am sure many beginners heard of this but done exactly know what it is. In a few words, I can say that linker creates an output file from relocatable objects.

The compiler is not one big program. It usually consists of up to a dozen smaller programs. Some programs, so-called program driver, control these programs. This driver can be a makefile and make.exe program. The whole compiler pieces are the preprocessor, the syntactic and semantic checker, code generator, the assembler, the optimizer, the linker, and make program.

Lets see a common example of the compiling procedure:

C compiling procedure

These programs are split into pieces for easier design and maintenance as each is a specialized program on its own. In many cases, the same program can be used for different programming languages. One disadvantage of running different tools will take a longer time than running one bigger program because there is a need to send information between programs.

There can be two types of libraries that can be linked to the program: static and dynamic. If a copy of libraries is physically part of the executable, we say the program is statically linked. If executable contains filenames that enable the loader to find references to the library, then we say the program is dynamically linked. Dynamic linking is more part of operating systems like MS Windows. In Embedded systems, usually, there is static library linking, where libraries become part of the program. This is why sometimes this is not a good choice to use pre-built universal libraries.

As you see, dynamic library linking benefits are obvious. But for dynamic linking, there should be at least some kind of operating system to have the ability to store dynamic libraries. I am not sure about embedded RTOS if there is some dynamic linking supported – maybe embedded Linux, I am not sure. But usually, we do statical linking when using external libraries when developing embedded projects. Some libraries are rich in their functionalities that smaller microcontrollers aren’t capable of storing all executables. For instance, Procyon AVRlib has many pre-built libraries, but linking to them may take huge amounts of program memory that smaller AVR microcontrollers won’t handle. Sometimes, it is better to write your own routines than a link to existing ones with many additional features and triggers.

2 Comments:

  1. Hi,
    Can someone suggest beginners guide for running WinAVR. I am not able to use it…
    Thanx

  2. Did you try reading this:
    https://scienceprog.com/avr-gcc-abc-1/
    …or post your problem in more specific way where is a problem.

Leave a Reply