Is the size of the libraries required for C++ (vs C) a concern in Embedded Linux systems? Most Embedded Linux systems likely include some C++ code, so this is probably not even a decision we need to make in many cases. However, often there is a need for a small initramfs that is used as part of the boot process (perhaps for software updates) before switching to the main root file system. In this case, it makes sense to keep the initramfs as small as possible, and we might be concerned here with the size of C++ libraries.
To find out what additional libraries are required when compiling with a C++ compiler vs C, a simple hello-world app was created. It was then compiled with gcc and g++. The outputs were then parsed with readelf to determine the required dynamic libraries. The results are shown below:
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
The sizes of packages for these libraries in an OpenEmbedded build are:
- libc: 1.4KiB (libm is inlcuded with libc)
- libstdc++6: 256KiB
- libgcc1: 204KiB
(The above sizes are compressed, so the actually will be some larger, but are useful for comparison.)
The installed sizes of libstdc++6 and libgcc1 on a ext3 file system are 1.4MiB and 750KiB.
It may also take slightly longer to load a C++ application as there is time required to dynamically load and link additional libraries. Is an extra 2MiB of libraries a big deal? It depends on your situation, but should be considered any time you are trying to create a small image.