Embedded GCC Libraries: newlib vs. nanolib

C/C++ compilers include a set of standard functions to be linked with user programs. They are called libc and libc++ respectively. For GCC, they are also called glibc and glibc++ (in the rest of this post, I would use glibc to mean both glibc and glibc++). Most of the functions are directly callable by the user programs, e.g. printf, but some are internal functions known to the compiler to support operations not directly supported by the target hardware. For example, double precision floating point add.

Traditional glibc is written for “big machines” such as Linux. For embedded use, it’s too bloated as embedded systems may not be running on top of an OS and advanced features such as locale (international language) support may not be needed. Even things like printf with full formatting and floating point support may take too much code for smaller microcontrollers.

Newlib” is written as a glibc replacement for embedded systems. It can be used with no OS (“bare metal”) or with a lightweight RTOS. Newlib is the default library for embedded GCC distributions. Besides being smaller than regular glibc, it is also more friendly toward embedded developers with its licensing terms.

However, even newlib is sometimes too bloated for memory constrained embedded systems based on microcontrollers. For these, there’s the newlib-nanolib, often shortened as nanolib. Nanolib is smaller and faster than newlib by code and data size reduction through optimization and removal of non-MCU features. Nanolib was originally developed as part of the GNU Arm Embedded Toolchain but is now the standard GCC embedded C library for microcontrollers. For ARM distributors, some optimized routines written in ARM assembly are used to further reduce the code size and run time.

One of the space saving technique that nanolib uses is to include a trimmed down version of printf that does not support floating point printout. If you need to print out floating point numbers (e.g. %f and %g format), you need to enable that explicitly.

If you use JumpStart C++ for Cortex, you can select whether to use newlib, nanolib, full printf etc. with GUI checkboxes.

Scroll to Top