A Library with ARM gcc and Eclipse

When I create a new bare-board project with the Eclipse based CodeWarrior 10.3 for my FRDM-KL25Z board and GNU gcc, then the ‘Library’ option is grayed out:

Library Option in New Project Wizard

Library Option in New Project Wizard

This does *not* mean that libraries cannot be built :-). In fact it is very easy to do this with the GNU tools and Eclipse, and here is how….

Step 1: Creating a normal project

I have created a normal application project with the New Project Wizard (menu File > New > Bareboard Project) using GNU gcc:

Application Project

Application Project

Step 2: Removing Application Files and Settings

For a library I do not need all the application specific files (like startup code) or linker and debugger files. They are all in the Project_Settings Folder, so I simply delete them:

Deleted Files for a Library Project

Deleted Files for a Library Project

Step 3: Adding Library Code

My library should implement some useful functionality (hopefully :-), and to have things simple here, I add this to the main.c file:

/*
* main file of my library
*
*/

int MultiplyBy2(int value)
{
  return value*2;
}

Step 4: Setting up the GCC Archiver

Now I need to tell the project settings that instead of building an application, I want a static library. This is configured in the project settings under the Build Artifact. I use the drop-down and select ‘ARM Cross Target Static Library‘ and press the ‘Apply‘ Button:

Static Library Build Artifact

Static Library Build Artifact

And to follow a common guideline, I use ‘lib’ to start the library name, and ‘.a’ as file extension in above dialog.

Using the above Artifact Type, it enables the ARM GCC Archiver in the options:

ARM GCC Archiver Option

ARM GCC Archiver Option

In the ‘General’ tab I configure the Archiver (ar) options: Usual options are -r (for replace or add files), -s to create a symbol table (gcc usually needs that) and -v for verbose (just so I know what is going on):

Archiver Options

Archiver Options

❗ The next step depends on which version of the ARM Ltd Eclipse plugins are used (I use here CodeWarrior for MCU10.3beta), as they have a minor glitch: the order of the arguments needs to be changed to match the arguments expected by the Archiver: the object files needs to be last in the list. For this I need to move the ${INPUTS} variable to the end of the Command Line Pattern:

Moving INPUT to the end of the command line pattern

Moving INPUT to the end of the command line pattern

With this, the command line pattern should look like this:

Command Line Pattern for Archiver

Command Line Pattern for Archiver

Step 5: Building the Library

That part is easy: compile and build the project as usual gives:

Invoking the Archiver

Invoking the Archiver

And the new library/archive shows up in my project structure:

Library Project with Generated Archive

Library Project with Generated Archive

Summary

Even if the New Project wizard does not offer a library option: creating a library with GNU gcc and ar(chiver) e.g. for Kinetis is a matter of a few minutes, and really easy. The minor thing with moving ${INPUT} I expect to be improved for the MCU10.3 final. Using libraries helps me to put again-and-again used software modules in libraries, so I need to compile and build them only once, and can re-use it over and over again.

Happy Archiving 🙂

Advertisements

8 thoughts on “A Library with ARM gcc and Eclipse

  1. With MCU 10.3 Production, the ‘Library’ option will be available for both ‘GCC-ARM’ and ‘FSL-ARM’ build tools selection. There is also a fix in place for the GCC Archiver command line pattern – such that creating a Kinetis library project will be an out of the box user experience.

    Like

  2. Pingback: Creating and using Libraries with ARM gcc and Eclipse | MCU on Eclipse

  3. Pingback: Creating a Library with Kinetis Design Studio | MCU on Eclipse

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s