Reduce Library Binary Size
You can use the following methods to reduce the size of the libraries you use in the Alexa Voice Service (AVS) Device SDK.
- Remove debug information from your binaries.
- Build the SDK with the
- Build and link static libraries.
Remove debug information
By default, binaries might contain debug information. This information is useful when analyzing dump files and troubleshooting application errors. However, this information is sometimes larger than the actual library code which occupies additional storage space.
To separate debug information from binaries, you can use the objcopy and strip utilities.
# Create a .debug file containing only debug information objcopy --only-keep-debug library.so library.so.debug # Remove debug information from original binary strip -g library.so # Add a link to debug information into stripped binary objcopy --add-gnu-debuglink=library.so.debug library.so
Build with MINSIZEREL
MINSIZEREL build option produces smaller binaries than the
RELEASE build. For more details about the SDK build options, see Build Type.
Build and link static libraries
The AVS Device SDK contains a large set of functions which you might not use in your application. If this is the case, you can build static libraries to reduce storage space and memory requirements. When you do this, the SDK drops any unused code that it doesn't use.
To use static libraries in the SDK
BUILD_SHARED_LIBS=OFF CMake parameters in your build.
The following example shows a full CMake build command on a Raspberry Pi, with shared libraries disabled.
cmake /home/pi/sdk-folder/sdk-source/avs-device-sdk \ -DGSTREAMER_MEDIA_PLAYER=ON \ -DPORTAUDIO=ON \ -DPKCS11=OFF \ -DPORTAUDIO_LIB_PATH=/home/pi/sdk-folder/third-party/portaudio/lib/.libs/libportaudio.a \ -DPORTAUDIO_INCLUDE_DIR=/home/pi/sdk-folder/third-party/portaudio/include -DCURL_INCLUDE_DIR=/home/pi/sdk-folder/third-party/curl-7.67.0/include/curl \ -DCURL_LIBRARY=/home/pi/sdk-folder/third-party/curl-7.67.0/lib/.libs/libcurl.so \ -DBUILD_SHARED_LIBS=OFF
Known issue with Windows
Static libraries don't always work when building the SampleApp on Windows with the MinGW environment. As a result, the executable fails with the following error:
Mingw-w64 runtime failure: 32 bit pseudo relocation at 00007FF7AC5986A6 out of range, targeting 00007FFC0DA448E0, yielding the value 00000004614AC236.`
This error depends on the particular compiler and features you have enabled. You can solve this problem in the following ways:
- Change the default compiler from clang++ to g++, effectively changing the enabled features that are causing problems.
- Building the application with shared libraries enabled.
To change the default compiler
Open your mingw.sh file and replace the following line:
export CC=`which clang` export CXX=`which clang++`
With the following line:
export CC=`which gcc` export CXX=`which g++`
Was this page helpful?
Last updated: Nov 12, 2021