Exhale: Automatic C++ API Documentation Generator
Exhale is a Sphinx extension designed to automatically generate C++ library API documentation. It integrates Doxygen's XML output with Sphinx, providing features like class, file, and page hierarchies within Sphinx-generated websites. Currently at version 0.3.7, Exhale is actively maintained with releases focusing on bug fixes and dependency updates.
Common errors
-
Exhale is not creating expected API documentation / malformed output.
cause Underlying Doxygen documentation has warnings or errors, leading to incorrect XML output that Exhale then processes incorrectly.fixInspect your Doxygen build logs and resolve all warnings and errors in your C++ code's Doxygen comments and configuration. Exhale's output fidelity is directly tied to Doxygen's accuracy. -
Failed to install `lxml` dependency during `pip install exhale`.
cause The `lxml` package has system-level dependencies (like `libxml2` and `libxslt`) which might be missing, particularly on Windows or minimal Linux environments.fixRefer to the `lxml` installation documentation for specific system-level library requirements and how to install them for your operating system. For many Linux systems, this involves `apt-get install libxml2-dev libxslt1-dev` (Debian/Ubuntu) or `yum install libxml2-devel libxslt-devel` (RHEL/Fedora). -
Generated API pages are not appearing in the Sphinx build output or linked in the navigation.
cause The `containmentFolder` specified in `exhale_args` is not a valid location (e.g., it's set to the Sphinx source root or the build directory), or the `library_root.rst` is not included in an `index.rst` toctree.fixEnsure `exhale_args['containmentFolder']` points to a *subdirectory* of your Sphinx source directory (e.g., `./api`) and that your main `index.rst` (or equivalent) contains a `.. toctree::` directive linking to this root, e.g., `api/library_root`. -
Duplicate functions/classes or incomplete information displayed in the Sphinx sidebar/API output.
cause Doxygen configuration issues leading to duplicate entries in the XML or Exhale misinterpreting relationships due to ambiguous Doxygen output.fixReview your Doxygen configuration, especially `INPUT`, `FILE_PATTERNS`, and `EXCLUDE` settings, to ensure only desired files are processed once. Address any Doxygen warnings about ambiguous documentation.
Warnings
- breaking Exhale dropped support for Python 2.7 in versions 0.3.x. Users must use Python 3.7+ (recommended 3.8+). Compatibility with specific Sphinx and Breathe versions is also critical.
- breaking The internal link generation scheme changed significantly in v0.2.0, potentially breaking existing internal links in documentation.
- gotcha Exhale's output heavily depends on valid Doxygen XML. Warnings or errors in your Doxygen build will likely result in unexpected, incorrect, or incomplete API documentation from Exhale.
- gotcha Windows users may encounter issues with excessively long file paths generated by Doxygen/Sphinx, even if Exhale attempts to handle them.
- gotcha The `containmentFolder` for Exhale's generated reStructuredText files *must* be a subdirectory of your Sphinx source directory and cannot be the root (`.`) or the Sphinx build output directory (`_build`).
Install
-
pip install exhale -
pip install sphinx>=2.0 breathe>=4.13.0 exhale
Imports
- generate
from exhale import generate
Quickstart
import os
import sys
# Add these to your conf.py after `extensions` list and other configurations
# Assuming your Doxygen XML output is in `_build/doxyoutput/xml` relative to docs/conf.py
# and your C++ source is in `../include` relative to docs/
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
'breathe',
'exhale'
]
# Breathe configuration
breathe_projects = {"My Project": "_build/doxyoutput/xml"}
breathe_default_project = "My Project"
# Exhale configuration
exhale_args = {
"doxygenIndexXMLPath": "_build/doxyoutput/xml/index.xml",
"containmentFolder": "./api",
"rootFileName": "library_root.rst",
"rootFileTitle": "Library API",
"doxygenStripFromPath": "..",
"createTreeView": True,
"exhaleExecutesDoxygen": True,
"exhaleDoxygenStdin": "INPUT = ../../include"
}
# Tell sphinx what the primary language being documented is.
primary_domain = 'cpp'
# Tell sphinx what the pygments highlight language should be.
highlight_language = 'cpp'
# If you choose to execute Doxygen separately, remove 'exhaleExecutesDoxygen' and 'exhaleDoxygenStdin'
# and ensure Doxygen output is generated before Sphinx build.
# Add 'api/library_root' to a toctree directive in your index.rst, e.g.:
#
# .. toctree::
# :maxdepth: 2
# :caption: Contents:
#
# api/library_root