Including a static library (.a)

  1. Building a Library for the XDK
  2. Binding a Library in the SDK

While the SDK already offers most functionalities regarding the XDK and networking protocols, users may wish to add their own libraries for specific functionalities. This section details how to build and bind a library into the XDK’s Software Development Kit.

Building a Library for the XDK

To be able to create your own libraries for the XDK, you first have to create a header file to your library (e.g. StaticLib.h) and an associated implementation file (e.g. StaticLib.c). Please make sure that your header file contains all function prototypes, type definitions and global variables used in the implementation file before continuing. To ensure your libraries will work properly when flashed on the XDK, please use the armGCC compiler provided with your XDK Workbench installation. To do so, please browse to the armGCC compiler binary folder using your windows command line. The default path for the armGCC compiler binary folder is C:\XDK-Workbench\armGCC\bin.

Create a library object file (e.g. StaticLib.o) using the command below. This command will build a library object file including all necessary flags for the cortex-m3 micro-controller on the XDK. Make sure to replace $PATH with the path of your implementation file.

arm-none-eabi-gcc $PATH\StaticLib.c -c -Wall -pedantic -mcpu=cortex-m3 -mthumb -o $PATH\StaticLib.o

Once the library object file was successfully created, build an archive file (e.g. StaticLib.a) using the command below. The archive file will work without any issues on the XDK. Make sure to replace $PATH with the path of your archive file.

arm-none-eabi-ar -r $PATH\StaticLib.a $PATH\StaticLib.o

To make these steps easily repeatable, you might consider creating a batch (.bat) file with these two command lines. Batch files can be run from terminal and execute the code written into it.

Binding a Library in the SDK

We strongly recommend making a copy of your current SDK before proceeding. This ensures that you still own a copy of the original SDK, in case the SDK gets corrupted during or after the editing process.

Browse to the SDK libraries folder and create the folder “OwnLibs”. The default path of the SDK libraries folder is C:\XDK-Workbench\SDK\xdk110\Libraries. Create a subfolder “include” and put your header files into it (e.g. StaticLib.h). Create another subfolder “source” and put your archive files into it (e.g. StaticLib.a). Afterwards, you need to make some changes in the makefiles within the common folder of the SDK. You can find the common folder by navigating to SDK > xdk110 > Common within your Project Explorer using the XDK Workbench.

Open the file “application.mk”. Browse down to the end of #Root paths to 3rd party packages on which xdk applications depends and add the following code snippet to it:

OWN_LIBRARIES_DIR = $(BCDS_LIBRARIES_PATH)/OwnLibs

fig1

This defines the path to your own archive and header files

Now, browse down to the end of BCDS_XDK_EXT_INCLUDES and add the following code snippet to it:

-isystem $(OWN_LIBRARIES_DIR)/include

Image

This sets the include path for the header file associated to your archive file. Now, to ensure that your archive file can be build within your applications, open the file “Libraries.mk”, browse to the end of BCDS_THIRD_PARTY_LIBS and add the following code snippet to it:

$(OWN_LIBRARIES_DIR)/source/StaticLib.a \

If the backslash at the end of the previous line is missing, add one, else this will cause issues.

Save all changes made and rebuild the SDK. Please note that this binding of your own libraries to the makefiles of the XDK is an easy approach and does not distinguishing between particular builds like release, debug or clean.