C/C++ Language SupportΒΆ

Integration with Doxygen and Breathe

C/C++ Language SupportΒΆ

Introligo integrates with Doxygen and Breathe to provide comprehensive C/C++ API documentation in Sphinx.

OverviewΒΆ

C/C++ documentation in Introligo uses the industry-standard Doxygen tool for extracting documentation from source code comments, combined with the Breathe Sphinx extension for seamless integration. This two-stage process provides rich, detailed API documentation.

FeaturesΒΆ

βœ… Industry Standard - Uses Doxygen, the de-facto C/C++ documentation tool βœ… Full C++ Support - Classes, templates, namespaces, inheritance βœ… Breathe Integration - Native Sphinx directives for C/C++ constructs βœ… Rich Formatting - Diagrams, graphs, cross-references βœ… Multi-File - Document entire codebases or specific files βœ… Auto-Configuration - Introligo auto-adds Breathe extension

PrerequisitesΒΆ

Required ToolsΒΆ

  1. Doxygen - Install from your package manager:

# Ubuntu/Debian
sudo apt-get install doxygen

# macOS
brew install doxygen

# Or download from https://www.doxygen.nl
  1. Breathe - Install via pip:

pip install breathe

Basic UsageΒΆ

Minimal ConfigurationΒΆ

# Global Doxygen configuration
doxygen:
  xml_path: "doxygen/xml"     # Where Doxygen outputs XML
  project_name: "myproject"

modules:
  calculator:
    title: "Calculator Functions"
    language: cpp
    doxygen_file: "calculator.h"

Configuration FieldsΒΆ

Field

Description

Required

language

Set to c or cpp

Yes

doxygen_file

Single header/source file

One of these

doxygen_files

List of multiple files

One of these

doxygen_class

Specific class name

One of these

doxygen_function

Specific function name

One of these

doxygen_namespace

Specific namespace

One of these

Global `doxygen` section:

Field

Description

Required

xml_path

Path to Doxygen XML output

Yes

project_name

Project identifier

Yes

How It WorksΒΆ

Two-Stage ProcessΒΆ

  1. Doxygen Stage: Extract documentation from C/C++ source

  2. Breathe Stage: Convert Doxygen XML to Sphinx RST

C/C++ Source Code
    ↓
Doxygen (generate XML)
    ↓
XML Output
    ↓
Introligo + Breathe
    ↓
Sphinx RST Files
    ↓
Beautiful Documentation!

WorkflowΒΆ

  1. Write Doxygen comments in your C/C++ code

  2. Run Doxygen to generate XML: doxygen Doxyfile

  3. Configure Introligo to point to the XML

  4. Generate docs with Introligo

  5. Build with Sphinx as usual

Complete ExampleΒΆ

Project StructureΒΆ

myproject/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ calculator.h      # Header with Doxygen comments
β”‚   └── calculator.cpp
β”œβ”€β”€ doxygen/
β”‚   β”œβ”€β”€ Doxyfile         # Doxygen configuration
β”‚   └── xml/             # Generated XML (output)
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ introligo_config.yaml
β”‚   └── (generated RST files)

Doxygen Configuration (Doxyfile)ΒΆ

# Basic Doxygen configuration
PROJECT_NAME           = "Calculator"
OUTPUT_DIRECTORY       = doxygen
GENERATE_XML           = YES      # ← Required for Breathe
GENERATE_HTML          = NO       # Optional
XML_OUTPUT             = xml      # ← This is what Introligo uses

# Input files
INPUT                  = src/
RECURSIVE              = YES
FILE_PATTERNS          = *.h *.hpp *.cpp

Introligo ConfigurationΒΆ

# Global Doxygen configuration
doxygen:
  xml_path: "../doxygen/xml"
  project_name: "calculator"

sphinx:
  project: "Calculator Library"
  html_theme: "furo"

modules:
  api_reference:
    title: "API Reference"
    description: "Complete C++ API documentation"

  calculator_module:
    parent: "api_reference"
    title: "Calculator Functions"
    language: cpp
    description: "Basic arithmetic operations"

    # Document specific files
    doxygen_files:
      - calculator.h
      - calculator.cpp

    overview: |
      The Calculator library provides simple arithmetic
      operations with error handling.

    usage_examples:
      - title: "Basic Usage"
        language: "cpp"
        code: |
          #include "calculator.h"

          int main() {
              int result = add(5, 3);
              std::cout << "Result: " << result << std::endl;
              return 0;
          }

Doxygen Comment StylesΒΆ

Qt StyleΒΆ

/*!
 * \brief Divide two numbers
 *
 * Performs division with zero-check.
 *
 * \param dividend The number to be divided
 * \param divisor The number to divide by
 * \param[out] result Pointer to store the result
 * \return true if successful, false if divisor is zero
 */
bool divide(int dividend, int divisor, int* result);

Class DocumentationΒΆ

/**
 * @class Calculator
 * @brief A simple calculator class
 *
 * This class provides basic arithmetic operations
 * for integer values with proper error handling.
 *
 * @author Your Name
 * @version 1.0
 * @date 2025-01-25
 */
class Calculator {
public:
    /**
     * @brief Constructor
     * @param precision Calculation precision level
     */
    Calculator(int precision = 0);

    /**
     * @brief Add two numbers
     * @param a First operand
     * @param b Second operand
     * @return Sum of a and b
     */
    int add(int a, int b) const;

    /**
     * @brief Get current precision
     * @return Current precision value
     */
    int getPrecision() const { return m_precision; }

private:
    int m_precision;  ///< Calculation precision
};

Namespace DocumentationΒΆ

/**
 * @namespace math
 * @brief Mathematical operations
 *
 * This namespace contains various mathematical
 * functions and utilities.
 */
namespace math {

/**
 * @brief Calculate factorial
 * @param n Input number (must be non-negative)
 * @return Factorial of n
 * @throws std::invalid_argument if n is negative
 */
int factorial(int n);

}  // namespace math

Advanced ConfigurationΒΆ

Document Specific ElementsΒΆ

Single File:

modules:
  calculator:
    language: cpp
    doxygen_file: "calculator.h"

Multiple Files:

modules:
  api:
    language: cpp
    doxygen_files:
      - "core.h"
      - "utils.h"
      - "types.h"

Specific Class:

modules:
  calculator_class:
    language: cpp
    doxygen_class: "Calculator"

Specific Function:

modules:
  add_function:
    language: cpp
    doxygen_function: "add"

Specific Namespace:

modules:
  math_namespace:
    language: cpp
    doxygen_namespace: "math"

Multiple ProjectsΒΆ

Document multiple C/C++ projects:

# Can't have multiple doxygen sections,
# but can organize with subdirectories

doxygen:
  xml_path: "doxygen_output/xml"
  project_name: "combined"

modules:
  lib1:
    language: cpp
    doxygen_files:
      - "lib1/api.h"

  lib2:
    language: cpp
    doxygen_files:
      - "lib2/core.h"

Breathe DirectivesΒΆ

Introligo generates these Breathe directives:

File DocumentationΒΆ

.. doxygenfile:: calculator.h
   :project: calculator

Class DocumentationΒΆ

.. doxygenclass:: Calculator
   :project: calculator
   :members:
   :undoc-members:

Function DocumentationΒΆ

.. doxygenfunction:: add
   :project: calculator

Namespace DocumentationΒΆ

.. doxygennamespace:: math
   :project: calculator
   :members:
   :undoc-members:

Best PracticesΒΆ

1. Use Clear Comment FormatΒΆ

/**
 * @brief One-line summary
 *
 * Detailed description here.
 *
 * @param name Parameter description
 * @return Return value description
 */

2. Document All Public APIsΒΆ

// Good - public function with doc
/**
 * @brief Public API function
 */
void publicFunction();

// OK - private function without doc
private:
    void privateHelper();  // Can use regular comments

3. Use @code Blocks for ExamplesΒΆ

/**
 * @brief Example function
 *
 * @code
 * int result = multiply(5, 3);
 * std::cout << result;  // Output: 15
 * @endcode
 */
int multiply(int a, int b);

4. Document Member VariablesΒΆ

class MyClass {
private:
    int m_count;        ///< Number of items processed
    bool m_enabled;     ///< Whether processing is enabled
    std::string m_name; /**< Name of the instance */
};

TroubleshootingΒΆ

Doxygen XML Not FoundΒΆ

Problem: Breathe projects: cannot find XML

Solution: Check paths in configuration:

doxygen:
  xml_path: "../doxygen/xml"  # Relative to docs directory

Verify XML was generated:

ls -la doxygen/xml/
# Should see index.xml and other XML files

Missing DocumentationΒΆ

Problem: Functions appear but have no description

Solution: Add Doxygen comments to your C/C++ code:

/** @brief Add this comment! */
void myFunction();

Breathe Not InstalledΒΆ

Problem: Extension error: Could not import extension breathe

Solution:

pip install breathe

Wrong Project NameΒΆ

Problem: Documentation doesn’t appear or shows wrong project

Solution: Match project names:

doxygen:
  project_name: "calculator"  # ← Must match

modules:
  calc:
    doxygen_file: "calc.h"  # ← Uses global project name

Example ProjectsΒΆ

Calculator LibraryΒΆ

See examples/c_project/ for a complete working example with: - Annotated C source files - Configured Doxyfile - Introligo configuration - Generated documentation

StructureΒΆ

examples/c_project/
β”œβ”€β”€ calculator.h          # Header with Doxygen comments
β”œβ”€β”€ calculator.c          # Implementation
β”œβ”€β”€ Doxyfile             # Doxygen config
β”œβ”€β”€ introligo_config.yaml # Introligo config
β”œβ”€β”€ doxygen/
β”‚   └── xml/             # Generated XML
└── docs/
    └── (generated docs)

Comparison with Other LanguagesΒΆ

Feature

C/C++

Python

Go

Tool

Doxygen

autodoc

go doc

Stages

2 (Doxygen + Breathe)

1 (Sphinx)

1 (Introligo)

Setup

⚠️ Complex

βœ… Simple

βœ… Simple

Features

βœ… Very Rich

βœ… Rich

⚠️ Basic

Diagrams

βœ… Yes

❌ No

❌ No

Templates

βœ… Full

N/A

N/A

See AlsoΒΆ

SummaryΒΆ

Introligo’s C/C++ support provides:

βœ… Industry-standard Doxygen integration βœ… Automatic Breathe configuration - Just specify files βœ… Flexible targeting - Files, classes, functions, or namespaces βœ… Rich documentation - Full Doxygen feature set βœ… Seamless Sphinx integration - Native RST output

Document your C/C++ projects with the power of Doxygen and the beauty of Sphinx!