Overview
Maintaining Application Binary Interface (ABI) stability is one of the most critical responsibilities when distributing shared libraries in Debian and Ubuntu ecosystems. The dpkg-gensymbols utility automates symbol tracking, preventing accidental breaking changes across package updates. This practical guide walks through compiling a sample shared library, generating baseline symbol definitions, and analyzing symbol diffs when exported functions evolve.
Installing Toolchains and Compiling a Shared Object
Begin by provisioning your build environment with the necessary Debian development utilities, compiler toolchains, and binary manipulation packages:

Set up an isolated workspace under /tmp containing the standard debian metadata directory, then switch into the newly created folder:
mkdir -p /tmp/gensymbols_demo/debian && cd /tmp/gensymbols_demo

Initialize the C source file libtest.c by pulling in the standard I/O header:
echo '#include <stdio.h>' > libtest.c

Next, append the initial API implementation, exporting a single function named func_alpha:
echo 'void func_alpha(void) { printf("Alpha v1\n"); }' >> libtest.c

Compile the source into a position-independent shared object (libdemo.so.1.0), embedding libdemo.so.1 as its internal SONAME:
gcc -fPIC -shared -Wl,-soname,libdemo.so.1 -o libdemo.so.1.0 libtest.c

Verify that the shared object built cleanly in the root of the workspace:
ls -l libdemo.so.1.0

Crafting Initial Symbol Definitions and Package Metadata
Ensure you are located in the demonstration root /tmp/gensymbols_demo before staging packaging files:
cd /tmp/gensymbols_demo

Populate debian/control by declaring libdemo as the source package identifier:
echo 'Source: libdemo' > debian/control

Append the corresponding binary package stanza to define libdemo1:
echo 'Package: libdemo1' >> debian/control

Designate target architecture support as any within debian/control:
echo 'Architecture: any' >> debian/control

Create the baseline symbols file debian/libdemo1.symbols, registering the SONAME alongside the #MINVER# version substitution macro:
echo 'libdemo.so.1 libdemo1 #MINVER#' > debian/libdemo1.symbols

Record the exported symbol func_alpha@Base and tie it to the initial release version 1.0:
echo ' func_alpha@Base 1.0' >> debian/libdemo1.symbols

Inspect the assembled debian/libdemo1.symbols file to confirm accurate symbol binding and version mapping:
cat debian/libdemo1.symbols

Extracting and Validating Symbols with dpkg-gensymbols
Return to the active root directory to begin package staging:
cd /tmp/gensymbols_demo

Replicate the standard Debian binary layout by establishing the destination library directory:
mkdir -p debian/libdemo1/usr/lib

Stage the compiled shared library into the target packaging hierarchy under its canonical SONAME:
cp libdemo.so.1.0 debian/libdemo1/usr/lib/libdemo.so.1

Invoke dpkg-gensymbols to scan the staged binary, reconcile the exposed interface against your baseline reference, and output the generated snapshot for version 1.0-1:
dpkg-gensymbols -p'libdemo1' -v'1.0-1' -Odebian/libdemo1.symbols.new

Print the resulting debian/libdemo1.symbols.new to inspect how package metadata and runtime symbols were harmonized:
cat debian/libdemo1.symbols.new

Tracking API Evolutions and Inspecting Symbol Diffs
Stay inside /tmp/gensymbols_demo as we introduce interface modifications:
cd /tmp/gensymbols_demo

Simulate upstream library expansion by introducing an additional public function, func_beta:
echo 'void func_beta(void) { printf("Beta added\n"); }' >> libtest.c

Rebuild the shared object directly into the staged package tree to reflect the upgraded API surface:
gcc -fPIC -shared -Wl,-soname,libdemo.so.1 -o debian/libdemo1/usr/lib/libdemo.so.1 libtest.c

Rerun dpkg-gensymbols against the revised binary, this time stamping the extraction with incremented package version 1.1-1:
dpkg-gensymbols -p'libdemo1' -v'1.1-1' -Odebian/libdemo1.symbols.new

Perform a unified diff between the baseline debian/libdemo1.symbols and the newly emitted debian/libdemo1.symbols.new file:
diff -u debian/libdemo1.symbols debian/libdemo1.symbols.new || true

The diff output distinctly highlights the newly introduced func_beta@Base symbol tagged alongside release 1.1-1, confirming that existing applications linked against func_alpha remain binary-compatible while consumer packages requesting the new function will automatically register dependencies on version 1.1-1 or higher. Leveraging dpkg-gensymbols provides automated safeguards against silent ABI breakage throughout the software release lifecycle.