C++ Academy · Lesson

API Versioning and ABI Stability

Plan for semantic versioning and protect ABI stability across releases.

Lesson 2 of 414 steps

API Versioning and ABI Stability is a free C++ Academy lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the C++ Academy learning path, and your progress syncs across the web and the CoddyKit app. The C++ Academy course includes 4 lessons in total.

Two Different Compatibilities

Two compatibility concerns:

  • API compatibility — source code that compiles against version N also compiles against N+1
  • ABI compatibility — binaries compiled against version N work with version N+1 without recompiling

Why ABI Matters

ABI compatibility lets shared libraries be upgraded without recompiling dependents. Critical for distributions, plugins, and long-lived applications.

What Breaks ABI

Many innocent-looking changes break ABI:

  • Adding/removing/reordering data members
  • Adding/removing virtual functions
  • Changing inheritance
  • Changing template parameters
  • Inline function changes (sometimes)

Semantic Versioning (SemVer)

Communicate compatibility through version numbers MAJOR.MINOR.PATCH:

  • MAJOR — breaking changes
  • MINOR — new features, backward compatible
  • PATCH — fixes

Versioning Headers

Provide version macros in your headers.

#define MYLIB_VERSION_MAJOR 2
#define MYLIB_VERSION_MINOR 1
#define MYLIB_VERSION_PATCH 3

SONAME for Shared Libraries

On Linux, shared libraries have a SONAME that encodes the major version. Linkers and the loader use it to find compatible versions.

# libmylib.so.2 -> libmylib.so.2.1.3
# SONAME = libmylib.so.2

Hiding Implementation Details

Stable ABIs require keeping the implementation out of headers. Use PIMPL (next lesson) to add or remove private members without affecting consumers.

Compiler ABI

C++ ABI varies between compilers (GCC vs MSVC use different name mangling and class layouts). Distribute binaries built with specific compilers, or stick to extern "C" interfaces.

Standard Library ABI

The standard library can also break ABI — though libstdc++ and libc++ have policies. Avoid std types in your stable public API if you need cross-version compatibility.

Adding Features Compatibly

Safe additions:

  • New free functions
  • New classes
  • New non-virtual member functions (with care)

Unsafe: changing classes that consumers have on stack or compiled in.

Tools for ABI Checking

Tools that compare two builds:

  • abidiff — compares ABI
  • abicompliance-checker — generates reports

Long-Term Strategy

Design for stability up front: small public API, opaque types, careful use of templates and inheritance. Once you ship, breaking ABI is expensive — pin major version bumps and communicate clearly.

Quick Check

Which change to a C++ class is most likely to break ABI?

Recap

API compatibility means source compatibility; ABI compatibility means binary compatibility. ABI is fragile — adding members, virtuals, or changing inheritance breaks it. Use SemVer, hide implementation with PIMPL, ship multiple major versions side by side, and run ABI checkers.

Free to start

Learn C++ with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
51
Lessons
203

Frequently Asked Questions

Is the “API Versioning and ABI Stability” lesson free?

Yes — any 3 lessons of the C++ Academy learning path, including “API Versioning and ABI Stability”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The C++ Academy course includes 4 lessons in total.

What will I learn in “API Versioning and ABI Stability”?

Plan for semantic versioning and protect ABI stability across releases. You practise C++ Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start C++ Academy?

No prior experience is required. C++ Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.

How long does the “API Versioning and ABI Stability” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this C++ Academy lesson?

Yes. Every C++ Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Header-Only vs Compiled Libraries
  2. API Versioning and ABI Stability
  3. Hiding Implementation with PIMPL
  4. Writing a Modern Header-Only Utility Library
← Back to C++ Academy