libc is a C standard library implementation targeted for embedded systems.
In order to conserve precious memory resources, this library does not supply the complete C standard library functionality. Instead, a subset of functions which are useful on bare-metal embedded systems has been selected. If you have a bare metal system and want to use the standard set of C functions, this library is for you!
Unlike many other C libraries that I've come across, this library implements unit tests and has addressed flaws in open-source implementations of the C standard library functions.
free are not included in this library. If you need dynamic memory allocation support, you can couple this library with the Embedded Artistry
libmemory, which contains implementations of
If you are interested in contributing to this project, please read the
Table of Contents
- About the Project
- Project Status
- Getting Started
- Need Help?
- Futher Reading
About the Project
libc is intended to provide a portable set of useful C standard library functions that allows quick bringup of new bare-metal embedded systems.
Additionally, we want to ensure a high-quality
libc implementation by ensuring that each function has unit test coverage. Many C library function implementations are untested and contain errors. We are fighting poor implementations by adding test coverage.
In order to conserve precious memory resources, this library does not supply the complete C standard library functionality. Instead, a subset of functions which are useful on bare-metal embedded systems has been selected. This selection has primarily been driven by my own experience in bare-metal development. If you need additional features, please open a feature request.
The functional implementations in this library have been selected for portability and quick bringup of new systems. There may be more efficient implementations for these functions, but often they are architecture specific.
free are not included in this library. Because memory allocation schemes vary greatly with embedded systems (some not even allowing dynamic memory), you will need to supply your own implementations based on your system's needs. You can also couple this library with the Embedded Artistry
libmemory, which contains implementations of
This library does not supply
errno support at this time.
The following portions of the C library have been implemented:
- abs, labs, llabs
- div, ldiv, lldiv
- heapsort, heapsort_r
- imaxabs, imaxdiv
- qsort, qsort_r
- rand family
- strtoX functions (many via
The following architectures are currently supported:
- Hooks for
- ARM architecture support
- Cross-compilation for ARM
- math.h and some definitions (INFINITY, NaN)
The following unit tests need to be added:
Maybe in the future:
errnosupport (enabled as a compile-time switch)
- CMocka must be installed on your system to compile the unit tests
- Doxygen must be installed to generate documentation
- Meson is used as the buildsystem
git-lfsis used to store binary files
gccshould be installed in order to compile the files
Meson Build System
The Meson build system depends on
To install on Linux:
sudo apt-get install python3 python3-pip ninja-build
To install on OSX:
brew install python3 ninja
Meson can be installed through
pip3 install meson
If you want to install Meson globally on Linux, use:
sudo -H pip3 install meson
If you are using OSX, you can install
adr-tools through Homebrew:
brew install adr-tools
If you are using Windows or Linux, please install
adr-tools via GitHub.
Getting the Source
This project uses
git-lfs, so please install it before cloning. If you cloned prior to installing
git-lfs, simply run
git lfs pull after installation.
This project is hosted on GitHub. You can clone the project directly using this command:
git clone --recursive firstname.lastname@example.org:embeddedartistry/libc.git
The library can be built by issuing the following command:
This will build all targets for your current architecture.
You can clean builds using:
You can eliminate the generated
Makefiles and buildresults using:
Output is currently limited to
x86_64, but cross-compiling for ARM will be implemented in the near future.
Currently the best method to use this project is to build it separately and copy the contents into your tree. I will improve this method to allow easier usage as a submodule.
include/ directory contents into your source tree.
Build artifacts are stored in the
buildresults folder. You will find a
libc folder which contains the compiled static library:
Copy the desired library to your project and add the library to your link step.
Example linker flags:
The tests for this library are written with CMocka. You can run the tests by issuing the following command:
By default, test results are generated for use by the CI server and are formatted in JUnit XML. The test results XML files can be found in
If you would prefer to see the test result summary printed to
stdout instead, simply use the following command:
CMOCKA_MESSAGE_OUTPUT=stdout make test
This repository enforces formatting using
You can auto-format your code to match the style guidelines by issuing the following command:
Formatting is enforced by the Jenkins build server which runs continuous integration for this project. Your pull request will not be accepted if the formatting check fails.
Documentation can be built locally by running the following command:
Documentation can be found in
buildresults/doc, and the root page is
You can also reach out on Twitter: mbeddedartistry.
If you are intersted in contributing to this project, please read our contributing guidelines.
Copyright © 2017 Embedded Artistry LLC
This project is licensed under the MIT License - see LICENSE file for details.
musl libc is licensed under the MIT License - see LICENSE file for details.
I'd like to thank the following individuals for their direct contributions on this project:
- @seekaddo (Documentation)
Many of the open-source function implementations used in this library have been pulled from two primary sources:
- Apple Open Source libc
- abs, atof, bsearch, div family, heapsort/qsort family, abs family, imax family, strtol/ll/ull
- fls, flsl, flsll
- strstr, strtok. strnstr, strnlen, strndup, strncpy, strncat, strlen, strdup, strcpy, strcat
- memmem, memcpy
- musl libc
- All ctype member functions (locale support removed)
- strrchr, strchrnul, strchr
- memset, memrchr
I have also used and improved the open-source
The initial groundwork of testing was implemented by referencing the libc-test project.