The Arduino library compiled and ready for linking

When you compile your ‘sketch’ with the Arduino IDE one of the steps it takes is to quietly compile, on-the-fly, all the library files that supply the popular classes and functions such as Serial, digitalWrite, analogWrite etc.

The reason the IDE does it like this is because the library code contains compile-time conditional statements that will generate different code depending on the microcontroller that you are targeting as well as its frequency.

If you’re using a real IDE, such as Eclipse, then it is just plain ugly to have to add all the library source files to your project and compile them each time you do a full build, not to mention the increased code size due to more objects being compiled in than you actually want to use.

Hence I’ve decided to compile up the Arduino library for popular microcontrollers and frequencies and make them available as a download from this site.

The table below allows you to cross reference a library filename from the MCU, frequency and features included in the library

Filename MCU Frequency
libard_0021_atmega168_16.a ATMega168 16MHz
libard_0021_atmega328P_16.a ATMega328 16MHz
libard_0021_atmega1280_16.a ATMega1280 16MHz
libard_0021_atmega2560_16.a ATMega2560 16MHz

Filename refers to the name of the library file. All libraries can be found in the lib sub-folder.

MCU is the name of the microcontroller that this library was compiled against.

Frequency is the frequency of the microcontroller that the library was compiled against.

The library header files, specifically HardwareSerial.h, supports the use of the PROGMEM_CONSTRUCTORS compile-time definition to work around the constructor/destructor memory location bug present in MCU’s that have more than 64K of flash memory. Click here to read my blog post that explains why this might be important to you

How to use it

This guide assumes that you are using the Eclipse IDE for development.

Step 1: Choose a library

Refer to the table above for the name of the library that corresponds to the MCU and frequency of the library that you would like to link against.

Step 2: Add the include directory to the compiler settings

Right-click on your project name in the Project Explorer window and choose Properties from the context menu. Expand C/C++ Build and click on Settings in the left pane. From the Tool Settings tab, locate AVR C++ Compiler and click on Directories. You will get a screen like this:


Click image to magnify it.

Use the ‘green plus’ toolbar button to add a new entry to the Include Paths. Browse to the folder where you installed the package, navigate down through the version of the Arduino library and either the ext (extended) or std (standard) folder and choose the include folder.

You will have to repeat the above steps for the AVR Compiler section on the left if you have any plain C files in your project. I never write bog-standard C any more so I don’t have to, but you might depending on your requirements.

Step 3: Add the library to the linker settings

Keep the project settings page open from Step 2 (above) and click on the Libraries option under the AVR C++ Linker section in the left pane. You will get a screen like this:


Click image to magnify it.

In the upper Libraries section, use the ‘green plus’ button to add the name of the library from the table above. Do not include the lib prefix and do not include the .a suffix. The above screenshot should make that clear.

In the lower Libraries Path section, use the ‘green plus’ button to add the name of the directory that contains the above library file.

That’s it, your done. You should now be able to compile and link programs against the Arduino libraries.

Download the setup package

Click here to go to the downloads page.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>