There is no special option in Kinetis Design Studio ‘New Project Wizard’ (NPW) to create a library (or archive). But it is really easy to create a library project.
Outline
This post shows how to create a library project in the Freescale Kinetis Design Studio (KDS) (version v2.0.0 used). But this approach applies to any Eclipse based IDE using the GNU ARM Eclipse plugins.
The approach is very simple:
- Create a normal project with the NPW
- Transform it into a library project
Creating the Project
After I have created a project with File > New > Kinetis Design Studio project:
Static Library Artifact Type
The first step is to transform the project type from an ‘Executable’ into a ‘Static Library’ one. The setting is in the project properties (menu Project > Properties > C/C++ Build > Settings > Build Artifact)
Change it to ‘Static Library’:
The artifact (output file of the build) extension and prefix get automatically adjusted. This concludes the settings of the project, it is really that easy.
Removing not needed files
The next step is to remove application specific files which have been added to the project by the wizard:
- Linker Files: the library does not need a linker file, the library is a collection of object files only.
- Startup Code: the startup code belongs to the application, usually the library does not provide the startup code.
- Debugger configuration and launch configuration files: we are debugging the application from the application project, not with the library project.
- Main.c: typically the library consists of library modules, and does not have a main(). So we can remove this file too.
So select the above files and delete them from the project (DEL key or use the context menu and use ‘Delete’).
Adding Library Functionality
After that, I can add the library functionality and files to the project. In this example I add an AES encryption functionality to the library:
Building the Library
Building the library is like building an application: use one of the Project > Build to build it.
With this, the library (or archive) file will show up in the project:
With this, I have created a library project. And I can add further files and functionality to the library.
Summary
To create a library with Kinetis Design Studio, create a normal application project, change the Artifact Type to ‘Static Library’, remove the application specific files (debugger files, linker file, startup code and main()). Then I can use it as a library project.
Happy Libraring 🙂
Links
- A Library with ARM gcc and Eclipse
- Creating and using Libraries with ARM gcc and Eclipse
- GNU ARM Eclipse Plugins
Great! Thanks! =)
LikeLike
Hey man, i was wondering: After doing this, how can i use the created library in another kinetis project? Thanks!
LikeLike
Hi Franco,
add the library to the linker settings, see https://mcuoneclipse.com/2013/02/12/creating-and-using-libraries-with-arm-gcc-and-eclipse/
I hope this helps,
Erich
LikeLike
As a student of Embedded systems i have to say that, you sir, are a life saver. Thanks a lot!
LikeLike
Hi Erich,
Is there anything special that needs to be done when linking an executable to a shared library, rather than a static one?
Thanks, Kevin
LikeLike
Hi Kevin,
nothing special is needed, except the usual points:
a) make sure your symbols are external in the library
b) link the library with the special -l option, without the lib prefix and without the .a extension, see https://mcuoneclipse.com/2013/02/12/creating-and-using-libraries-with-arm-gcc-and-eclipse/
I hope this helps,
Erich
LikeLike
Thanks Erich. I was missing a tick in a box which put the “lib” prefix on the output file. All works now.
LikeLike
Hi Erich, I’ve got a strange problem with a new KDS project. I’m linking to a shared library from my main application however during linking, I get the following errors:
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: TestProject.elf section `.interp’ will not fit in region `m_cfmprotrom’
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: section .dynamic loaded at [0001a018,0001a0cf] overlaps section .romp loaded at [0001a018,0001a03b]
makefile:53: recipe for target ‘TestProject.elf’ failed
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: region `m_cfmprotrom’ overflowed by 2780 bytes
Have you ever come across anything like this before? If I then remove the shared library from the Linker/Libraries list, the problems go away. There are no linker files associated with the shared library nor are there any startup files. I’m puzzled
LikeLike
Hi Kevin,
yes, seen something like this. First, make sure that you build the library with the -g (default debug level) option.
Second, it seems to me that your library includes constant data for the m_cfmprotrom section. Could it be that your library has included the startup code (usually the startup code has this?).
I hope this helps,
Erich
LikeLike
Hi Erich, I’ve turned on the “-g” option for the library. Initially there was a duplicate startup file which I’ve now removed but this hasn’t fixed the problem. I’m now getting the following errors (sorry, its a lot to pick through):
arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -g3 -T “C:/Users/kevin/workspace.kds/MyProject/Project_Settings/Linker_Files/ProcessorExpert.ld” -Xlinker –gc-sections -L”C:/Users/kevin/workspace.kds/MyProject/Project_Settings/Linker_Files” -L”C:\Users\kevin\workspace.kds\MyLibrary\Debug” -Wl,-Map,”MyProject.map” -specs=nano.specs -specs=nosys.specs -pie -o “MyProject.elf” ./Sources/main.o ./Project_Settings/Startup_Code/startup.o -lMyLibrary
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: section .dynamic loaded at [00012228,000122ff] overlaps section .romp loaded at [00012228,0001224b]
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: error: required section ‘.rel.plt’ not found in the linker script
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: final link failed: Invalid operation
LikeLike
It seems to me that you are trying to build a dynamic library? Are you sure you have selected a static library?
LikeLike
I think this is the main culprit:
section .dynamic loaded at [00012228,000122ff] overlaps section .romp loaded at [00012228,0001224b]
LikeLike
No, I think this is not the only thing. Try to start with a static library created with only one file (no startup code, etc, just a single file with a single function). Then add more files.
LikeLike
Or this:
error: required section ‘.rel.plt’ not found in the linker script
LikeLike
This indicates a relocation section. Make sure you create a static (not dynamic) library project.
I hope this helps.
LikeLike
Hi Erich, I actually wanted to create a dynamic library but then common sense took over and I realised that this wasn’t possible. Doh. Static library it is. Sorry for my stupidity.
LikeLike
No problem :-). For a dynamic library you would have to write/use a library loader in your application (which you probably don’t need/want). The great thing is that the GNU tools support this, which is very useful say in a embedded Linux environment. Less common in a microcontroller area.
LikeLike
I’m looking for good software-based AES implementations for microcontrollers. Is the library you created here available for download? I thought I recalled seeing some AES functionality in a PEx component in an article here, but I haven’t been able to find it.
LikeLike
Hi Lee,
I have not published that AES library shown in that screenshot, but sounds maybe I should (if I find time)?
LikeLike
Hi Erich,
That would certainly be helpful, yes. 🙂
LikeLike
Pingback: How to use Custom Library Names with GNU Linker and Eclipse | MCU on Eclipse
Pingback: Managing Project and Library Dependencies with Eclipse CDT | MCU on Eclipse