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:
- A C/C++ compiler (such as GCC, Clang, or MSVC)
- CMake (version 3.5 or higher)
- A build automation tool (such as Make or Ninja)
- NASM or YASM (highly recommended for x86/x86_64 assembly optimizations)
Step-by-Step Build Instructions
Follow these steps to download, configure, and compile
libaom as a shared library using the command-line
interface.
- Clone the Repository: Fetch the official source code from the AOMedia Git repository.
git clone https://aomedia.googlesource.com/aom
cd aom- Create a Build Directory: It is best practice to
perform an out-of-source build by creating a dedicated
builddirectory.
mkdir build_shared
cd build_shared- Configure with CMake: Run the
cmakecommand while explicitly setting the-DBUILD_SHARED_LIBS=1flag. This flag instructs the build system to generate dynamic libraries instead of static ones.
cmake .. -DBUILD_SHARED_LIBS=1 -DCMAKE_BUILD_TYPE=Release- 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.
- On Linux, look for
libaom.so. - On macOS, look for
libaom.dylib. - On Windows, look for
aom.dlland its corresponding import libraryaom.lib.
To install the compiled shared library and its development headers onto your system, execute the installation command with administrative privileges:
sudo make installPotential 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.