Skip to content

Manage pre-compiled libraries

emCode also manages a variant for the local and user’s libraries, the pre-compiled libraries.

The pre-compiled libraries are already built and ready to use.

The local pre-compiled libraries are part of the project and located on the same folder as the main sketch,

The user’s pre-compiled libraries are located on the libraries sub-folder under the sketchbook folder, along the header file of the library.

Like standard libraries, pre-compiled libraries require to be explicitly mentioned by the #include statement on the main sketch and mentioned on the main Makefile.

Generate a pre-compiled library

Before generating a pre-compiled library from a local library,

  • Check the header and code files are inside a sub-folder.
LocalLibrary/
├── library.properties
└── src
    ├── LocalLibrary.cpp
    └── LocalLibrary.h

In the example above, LocalLibrary.h and LocalLibrary.cpp are inside the sub-folder LocalLibrary.

To generate a pre-compiled library,

  • Presss Ctrl+Shift+P and type Tasks: Run Task.

  • Select the Archive target and launch it.

==== Archive ====
---- Generate ----
7.1-ARCHIVE       LocalLibrary/src/cortex-m0plus
---- Update ----
7.3-ARCHIVE       LocalLibrary/library.properties
==== Archive done ====

In the library sub-folder, the new folder cortex-m0plus has been created cortex-m0plus to include the new file LocalLibrary.a. This is the pre-compiled library.

LocalLibrary/
├── library.properties
└── src
    ├── cortex-m0plus
       ├── libLocalLibrary.a
       └── ReadMe.md
    ├── LocalLibrary.cpp
    └── LocalLibrary.h

The library.properties file has been updated with

precompiled=true
ldflags=-lLocalLibrary

The folder cortex-m0plus is specific for the Cortex-M0+: the pre-compiled library is valid for the board or MCU it has been compiled against. However, it may not work properly on other Cortex-M0+-based MCUs.

The ReadMe.md file describes the configuration used for generating the pre-compiled library.

LocalLibrary
Pre-compiled library
Info
Date Time 2025-02-19 16:53:03
Platform
Platform Earle F. Philhower RP2040 4.4.4 for Arduino 2.3.2
Board Raspberry Pi Pico (rpipico)
Arduino
Arduino CLI release 1.1.1
Tools
Make GNU Make 4.3
Tool-chain arm-none-eabi-gcc (GCC) 14.2.0
emCode
Edition emCode release 14.6.11
Template emCode release 14.0.6
Makefile RaspberryPiPico release 14.6.10
Configuration Raspberry Pi Pico RP2040 (DebugProbe CMSIS-DAP) release 14.5.0

For more information,

Use a pre-compiled library

The pre-compiled user’s and local libraries are used the same way as user’s and local libraries.

Share a pre-compiled library

To share the pre-compiled library,

  • Just take the folder with the header files and the pre-compiled library, here LocalLibrary.h and LocalLibrary.a, along with library.properties.

Remember this pre-compiled library is only valid for the board or MCU it has been compiled against. Do not use it with another board or MCU as it may not work properly.

Remove a pre-compiled library

To remove the pre-compiled libraries,

  • Check the header and code files are inside a sub-folder.
LocalLibrary/
├── library.properties
└── src
    ├── cortex-m0plus
       └── libLocalLibrary.a
    ├── LocalLibrary.cpp
    └── LocalLibrary.h

In the example above, the sub-folder LocalLibrary should contain LocalLibrary.h and LocalLibrary.cpp.

  • Presss Ctrl+Shift+P and type Tasks: Run Task.

  • Select the Unarchive target and launch it.

==== Unarchive ====
---- Remove ----
7.4-UNARCHIVE     LocalLibrary/src/cortex-m0plus
---- Update ----
7.5-UNARCHIVE     LocalLibrary/library.properties
==== Unarchive done ====

The archive LocalLibrary.a has been removed and the library.properties file has been updated back to its initial content.

LocalLibrary/
├── library.properties
└── src
    ├── LocalLibrary.cpp
    └── LocalLibrary.h