what is Doxygen?
Doxygen is a widely used documentation generator for programming languages such as C, C++, Java, Python, and more. It helps developers automatically create clear and organized documentation directly from annotated source code. Initially developed in 1997 by Dimitri van Heesch, Doxygen has grown in popularity due to its simplicity, flexibility, and the professional quality of its output.
The development of Doxygen is currently maintained by a community of contributors, and it continues to receive updates to support modern programming languages and features. It is an open-source tool, freely available for anyone to use and modify. The source code is hosted on GitHub: https://github.com/doxygen/doxygen.
Doxygen is considered free software, distributed under the GNU General Public License (GPL), which means it can be used, modified, and shared freely. Its long-standing presence and active maintenance make it a reliable choice for developers and teams who want to produce professional documentation efficiently.
By using Doxygen, developers can ensure that their code is well-documented, easier to maintain, and more understandable for both current and future team members.
Installation
Installing Doxygen on Windows
Go to the official Doxygen website: https://www.doxygen.nl/download.html
Download the Windows installer (usually a
.exefile).Run the installer and follow the setup instructions. You can keep the default settings unless you have specific preferences.
During installation, make sure to select the option to add Doxygen to your system PATH. This allows you to run Doxygen from the Command Prompt.
Testing the Installation on Windows:
Open Command Prompt and type:
doxygen --version
If the installation is successful, you will see the version number of Doxygen displayed.
Installing Doxygen on Linux
Most Linux distributions include Doxygen in their package manager.
For Ubuntu/Debian-based systems, use:
sudo apt update
sudo apt install doxygen
For Fedora/Red Hat-based systems, use:
sudo dnf install doxygen
Testing the Installation on Linux:
Open the terminal and type:
doxygen --version
If Doxygen is correctly installed, you will see its version number printed on the screen.
Tip: You can also install Doxygen with Graphviz if you want to generate diagrams in your documentation. On Linux, this can be done with:
sudo apt install graphviz
or on Fedora:
sudo dnf install graphvizBasic Usage
Once Doxygen is installed, you can start generating documentation for your project. The basic workflow involves creating a configuration file called Doxyfile and running Doxygen.
Step 1: Creating a Doxyfile
Open a terminal (or Command Prompt on Windows) in your project directory and run:
doxygen -g
This command generates a default Doxyfile in your current directory. The Doxyfile contains all settings needed to control how documentation is generated.
You can open Doxyfile with any text editor to modify options, such as:
PROJECT_NAME– your project’s nameOUTPUT_DIRECTORY– where the documentation will be savedEXTRACT_ALL– whether to document all elements, even without comments
Step 2: Running Doxygen
Once your Doxyfile is ready, simply run:
doxygen Doxyfile
Doxygen will scan your source code and generate documentation in the output folder specified in the Doxyfile.
Step 3: Viewing the Documentation
By default, Doxygen generates HTML documentation. To view it:
Open the output directory (usually
html/inside the folder specified).Open
index.htmlin your web browser.You should see a navigable documentation page with all your classes, functions, and files organized.
Tip: You can also generate PDF or LaTeX documentation by enabling the corresponding options in the Doxyfile, but HTML is usually the easiest way to start and share documentation.
Writing Comments in Doxygen
Doxygen generates documentation from special comments in your source code. These comments can describe functions, parameters, return values, classes, files, and more.
1. Comment Styles
Doxygen supports several comment styles:
C-style block comments:
/**
* This is a Doxygen comment
*/
Single-line comments:
/// This is also a Doxygen comment
C++ style block with double slashes:
/*!
* This is another valid style
*/
2. Common Tags
Some of the most commonly used Doxygen tags:
| Tag | Description |
|---|---|
@brief | A short description of the function or class |
@details | A longer, detailed explanation |
@param | Description of a function parameter |
@return | Description of the return value |
@file | Description of the file |
@see | Reference to related functions or classes |
@author | Author of the code |
Tips for Writing Good Comments:
Keep
@briefshort (1–2 lines).Use
@detailsfor extra explanation if needed.Always document parameters and return values.
Be consistent with your comment style throughout the project.
Examples: Practical Doxygen Demonstrations
In this section, we provide practical examples to show how Doxygen can generate clear and useful documentation for your code. These examples highlight common features like documenting functions, parameters, return values, classes, and grouping related code elements.
/**
* @brief Computes the factorial of a number
* @details This function uses a simple recursive approach
* to calculate the factorial of a non-negative integer.
* @param n The non-negative integer for which to calculate factorial
* @return The factorial of the number
* @throws std::invalid_argument If n is negative
*/
int factorial(int n) {
if (n < 0) {
throw std::invalid_argument("Negative input not allowed");
}
if (n == 0 || n == 1) return 1;
return n * factorial(n - 1);
}
#include
/**
* @brief Represents a simple bank account
* @details Provides methods for deposit, withdrawal, and balance checking
* @defgroup BankAccountGroup Bank Account Functions
*/
class BankAccount {
public:
/**
* @brief Constructor to initialize a bank account
* @param name Name of the account holder
* @param initial_balance Starting balance
*/
BankAccount(const std::string& name, double initial_balance);
/**
* @brief Deposit money into the account
* @param amount Amount to deposit
* @ingroup BankAccountGroup
*/
void deposit(double amount);
/**
* @brief Withdraw money from the account
* @param amount Amount to withdraw
* @return True if successful, false if insufficient funds
* @ingroup BankAccountGroup
*/
bool withdraw(double amount);
/**
* @brief Get the current balance
* @return Current balance
* @ingroup BankAccountGroup
*/
double getBalance() const;
private:
std::string accountHolder;
double balance;
};
/**
* @file shapes.h
* @brief This file contains shape types and related utilities
* @author Pouya
* @date 2025-11-05
*/
/**
* @brief Types of geometric shapes
* @details This enum lists common shapes used in geometry calculations.
*/
enum ShapeType {
CIRCLE, /**< Circle shape */
SQUARE, /**< Square shape */
TRIANGLE /**< Triangle shape */
};
/**
* @brief Calculate the perimeter of a shape
* @param type Type of shape
* @param size Length of side or radius
* @return Perimeter of the shape
* @warning Only positive values of size are allowed!
* @todo Add support for more shapes like rectangle and pentagon
*/
double calculatePerimeter(ShapeType type, double size) {
switch(type) {
case CIRCLE:
return 2 * 3.14159 * size; // size is radius
case SQUARE:
return 4 * size; // size is side length
case TRIANGLE:
return 3 * size; // equilateral triangle
default:
return 0;
}
/**
* @brief Compute the area of a rectangle
* @param width Width of the rectangle
* @param height Height of the rectangle
* @return Area of the rectangle
* @see calculatePerimeter() for perimeter calculation
*/
double calculateRectangleArea(double width, double height) {
return width * height;
}
Conclusion
Doxygen is a powerful and easy-to-use tool for generating clear, organized documentation directly from your source code. By using Doxygen, developers can save time, improve code readability, and ensure that both current and future team members can understand the project quickly.
Whether you are working on a small personal project or a large professional codebase, documenting your code with Doxygen makes it more maintainable and professional. Its open-source nature, active development, and compatibility with multiple programming languages make it a reliable choice for any developer who wants high-quality documentation with minimal effort.
Start adding Doxygen comments to your code today, and see how it transforms your documentation workflow!
References
van Heesch, D. (n.d.). Doxygen Manual. Doxygen. Retrieved November 5, 2025, from https://www.doxygen.nl/manual/index.html
Doxygen. (n.d.). GitHub Repository. GitHub. Retrieved November 5, 2025, from https://github.com/doxygen/doxygen
Stack Overflow. (n.d.). Doxygen examples and usage. Stack Overflow. Retrieved November 5, 2025, from https://stackoverflow.com/questions/tagged/doxygen
