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:
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:
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:
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:
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:
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):
❗ 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:
With this, the command line pattern should look like this:
Step 5: Building the Library
That part is easy: compile and build the project as usual gives:
And the new library/archive shows up in my project structure:
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 🙂
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.
LikeLike
Thanks, that’s good news!
LikeLike
Pingback: Creating and using Libraries with ARM gcc and Eclipse | MCU on Eclipse
Pingback: Creating a Library with Kinetis Design Studio | MCU on Eclipse
Hi Erich,
I followed step 4 but i am not getting any “GCC Archiver” option.
LikeLike
Hi Sidaray,
have you pressed the ‘Apply’ button as written in step 4?
LikeLike
Hi Erich,
After pressing build button i am getting below error.
mingw32-make: *** No rule to make target `all’. Stop.
LikeLike
Hi Sidray,
either you have not correctly configured the project, or not done a project > clean? See https://mcuoneclipse.com/2012/03/12/no-rule-to-make-target/
LikeLike