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ΒΆ
Doxygen - Install from your package manager:
# Ubuntu/Debian
sudo apt-get install doxygen
# macOS
brew install doxygen
# Or download from https://www.doxygen.nl
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ΒΆ
Doxygen Stage: Extract documentation from C/C++ source
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ΒΆ
Write Doxygen comments in your C/C++ code
Run Doxygen to generate XML: doxygen Doxyfile
Configure Introligo to point to the XML
Generate docs with Introligo
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ΒΆ
JavaDoc Style (Recommended)ΒΆ
/**
* @brief Add two integers
*
* This function performs addition of two integer values
* and returns the result.
*
* @param a The first integer
* @param b The second integer
* @return The sum of a and b
*
* @code
* int result = add(5, 3); // result = 8
* @endcode
*/
int add(int a, int b);
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!