Embedded C program libraries and linking

What is compilation of program 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.

Compiler is not one big program. It usually consist of up to a dozen smaller programs. These programs are controlled by some program so called “program driver”. This driver can be a makefile and make.exe program. The pieces of whole compiler are: the preprocessor, the syntactic and semantic checker, code generator, the assembler, the optimizer, the linker and make program.

Lets see common example of compiling procedure:

embedded_compiler

These programs are split in pieces for easier design and maintain as each is specialized program in its own. In many cases same program can be used for different programming languages. One disadvantage of running different tools will take longer time that running one bigger program. Because there is need to send information between programs.

There can be two types of libraries that can be linked to program: static and dynamic. If a copy of libraries is physically part of executable, then we say program is statically linked. If executable contains filenames that enable loader to find references to library then we say 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 program. This is why sometimes this is not good choice to use pre-built universal libraries.

static_vs_dynamic_linking

As you see dynamic library linking benefits are obvious. But for dynamic linking there should be at least some kind of operation system to have 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 arent capable to store all executable. For instance Procyon AVRlib has a bunch of 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 link to existing ones where are many additional features and triggers includes.

Blogsphere: TechnoratiFeedsterBloglines
Bookmark: Del.icio.usSpurlFurlSimpyBlinkDigg
RSS feed for comments on this post
 |  TrackBack URI for this post

New on WinAVR Tutorial
Running TX433 and RX433 RF modules with AVR microcontrollers,
Sometimes in embedded design you may want to go wireless. Might be you will want to log various readi …
Programming AVR ADC module with WinAVR,
Most of AVR microcontrollers have Analog to Digital Converter (ADC) integrated in to chip. Such solut …
New on WinARM Tutorial
What are differences between WinARM and WinAVR,
Everyone who is working with AVR microcontrollers knows this powerful tool – WinAVR (http://win …
LPC2000 watchdog timer,
As in all microcontrollers watchdog timers purpose isto reset microcontroller after reasonable amount …

2 Responses to “Embedded C program libraries and linking”

  1. Anurag Says:

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

  2. scienceprog Says:

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

Leave a Reply