How to Build libaom as a Shared Library?

Building the Alliance for Open Media (AOM) AV1 codec library (libaom) as a shared library (.so, .dylib, or .dll) instead of the default static library (.a or .lib) requires passing a specific flag to CMake during the configuration process. By default, the libaom CMake build system is configured to generate a static archive to maximize performance and portability. However, you can easily override this behavior by enabling the standard CMake BUILD_SHARED_LIBS variable, allowing for dynamic linking in your multimedia applications.

Prerequisites and Dependencies

Before configuring the build, ensure your system has the necessary build tools and dependencies installed. You will need:

Step-by-Step Build Instructions

Follow these steps to download, configure, and compile libaom as a shared library using the command-line interface.

  1. Clone the Repository: Fetch the official source code from the AOMedia Git repository.
git clone https://aomedia.googlesource.com/aom
cd aom
  1. Create a Build Directory: It is best practice to perform an out-of-source build by creating a dedicated build directory.
mkdir build_shared
cd build_shared
  1. Configure with CMake: Run the cmake command while explicitly setting the -DBUILD_SHARED_LIBS=1 flag. This flag instructs the build system to generate dynamic libraries instead of static ones.
cmake .. -DBUILD_SHARED_LIBS=1 -DCMAKE_BUILD_TYPE=Release
  1. Compile the Library: Compile the source code using your preferred build tool. If you are using Make, you can speed up the compilation by utilizing multiple CPU cores.
make -j$(nproc)

Verifying and Installing the Output

Once the build process completes successfully, you can verify the existence of the shared library file within your build directory.

To install the compiled shared library and its development headers onto your system, execute the installation command with administrative privileges:

sudo make install

Potential Configuration Conflicts

When forcing libaom to build as a shared library, be aware that certain internal unit tests or specific architectural optimizations can occasionally conflict with Position Independent Code (-fPIC) requirements. If you encounter compilation errors related to relocation or linking, you can explicitly ensure PIC is enabled by appending -DCMAKE_POSITION_INDEPENDENT_CODE=ON to your initial CMake configuration command.