Document your source code with Doxygen on Linux (2023)

When trying to familiarize yourself with someone else's project, you usually appreciate the comments left behind that help you understand the meaning of their code. In the same way, whenever you are programming, whether for yourself or for others, it is good practice to comment your own code. All programming languages offer a special syntax to mark a word, a line, or a whole section as a comment. Those areas are then ignored by the compiler or interpreter when the source code is processed.

Comments don't take the place of documentation, but there is a way to use your comments to produce documentation easily. MeetDoxygen, an open source tool for generating HTML or LaTeX documentation based on comments in the code. Doxygen enables you to provide a comprehensive overview of the structure of your code without additional effort. While Doxygen is mainly used to document C++, you can use it for many other languages, like C, Objective-C, C#, PHP, Java, Python, and more.

To use Doxygen, you simply comment your source code in a syntax that Doxygen can read. Doxygen then walks through your source files and creates HTML or LaTeX documentation based on those special comments. The C++ example project below will illustrate how the source code is commented and how the documentation is generated from it. The example is available on GitHub, and I will also include references to different sections of the Doxygen manual and documentation.

[ Download now: Doxygen cheat sheet ]

Install Doxygen on Linux

On Fedora, Doxygen is available as a package. Open a terminal and run:

sudo dnf install doxygen

On Debian-based systems, you can install it by running:

sudo apt-get install doxygen

Usage

Once installed, all you need is a project with Doxygen-compatible comments and a Doxyfile, a configuration file that controls the behavior of Doxygen.

Note: If you stick to the related example project on GitHub, you can omit the next step.

If there is no Doxyfile yet, you can simply let Doxygen generate a standard template. To do so, navigate to the root of your project and run:

doxygen -g

The -g stands for generate. You should now notice a newly created file called Doxyfile. You can invoke Doxygen by simply running:

doxygen

You should now notice two newly created folders:

  • html/
  • latex/

By default, Doxygen outputs LaTeX-formatted documentation as well as HTML-based documentation. In this article, I will focus only on HTML-based documentation. You can find out more about LaTeX output in the official Doxygen documentation, in the Getting started section.

Double click on html/index.html to open the actual HTML documentation. With a blank configuration, it probably looks like the screenshot below:

Document your source code with Doxygen on Linux (1)

Image by:

(Stephan Avenwedde, CC BY-SA 4.0)

Now it's time to modify the Doxyfile and add some special comments to the source code.

More Linux resources

Linux networking cheat sheet

SELinux cheat sheet

Linux common commands cheat sheet

What are Linux containers?

Our latest Linux articles

(Video) Doxygen - Documentation For Your Programs - Installing, Setting Up, And Running Tutorial

Doxyfile

The Doxyfile allows you to define tons of adjustment possibilities, so I will describe only a very small subset. The settings correspond to the Doxyfile of the example project.

Line 35: Project name

Here you can specify the project name, which will be visible in the header line and the browser tab.

# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by
# double-quotes, unless you are using Doxywizard) that should identify the
# project for which the documentation is generated. This name is used in the
# title of most generated pages and in a few other places.
# The default value is: My Project.

PROJECT_NAME = "My Project"

(Video) Doxygen Quick Guide 2021 | FREE Code Documentation tool

Line 47: Project brief description

The brief description will also be shown in the header but in a smaller font.

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
# quick idea about the purpose of the project. Keep the description short.

PROJECT_BRIEF = "An example of using Doxygen in C++"

Line 926: Inclusion of subdirectories

Allow Doxygen to walk recursively through subdirectories to find source and documentation files.

# The RECURSIVE tag can be used to specify whether or not subdirectories should
# be searched for input files as well.
# The default value is: NO.

RECURSIVE = YES

Line 1769: Disable LaTeX output

If you are just interested in the HTML output, you can disable the LaTeX code generation using this switch.

# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.

# The default value is: YES.

GENERATE_LATEX = NO

After every change, you can run Doxygen again to check whether your changes have had the desired effect. If you just want to check which modification an existing Doxyfile has, invoke Doxygen with the -x switch:

Document your source code with Doxygen on Linux (2)

Image by:

(Stephan Avenwedde, CC BY-SA 4.0)

As with the command diff, Doxygen displays only the differences between the actual Doxyfile and the template.

(Video) Doxygen Basics

Special comments

Doxygen reads the sources and checks each file for special comments. Based on those comments and keywords, it builds up the HTML documentation. The anatomy of the special comments can be well explained using the header file of the class ByteStream, as shown in the GitHub example linked above.

I will look at the constructor and destructor as an example:

/*! @brief Constructor which takes an external buffer to operate on
*
* The specified buffer already exist.
* Memory and size can be accessed by buffer() and size().
*
* @param[in] pBuf Pointer to existing buffer
* @param[in] size Size of the existing buffer
*/

ByteStream(char* pBuf, size_t size) noexcept;

There are different flavors of formatting a special comment block. I prefer to start the comment in the Qt-style (/*!) and add an asterisk (*) before each line. The block then ends with an asterisk followed by a forward slash (*/). To get an overview of the different style options, refer to the Doxygen manual, in the section Documenting the code.

Comments in Doxygen are divided into two sections, a brief description and a detailed description. Both sections are optional. In the code sample above, the comment block refers to the following line of code, the declaration of a constructor. The sentence behind the @brief will be shown in the compact class overview:

Document your source code with Doxygen on Linux (3)

Image by:

(Stephan Avenwedde, CC BY-SA 4.0)

After a blank line (blank lines are treated as paragraph separators), the actual documentation for the constructor begins. With the @param[in/out] keyword, you can mark the arguments passed to the constructor, and Doxygen will make a clear argument list from it:

Document your source code with Doxygen on Linux (4)

Image by:

(Stephan Avenwedde, CC BY-SA 4.0)

Note that Doxygen automatically creates a link to the mentioned buffer() and size() method in the comment. In contrast, the comment before the destructor declaration won't have any effect on Doxygen as it is not recognized as a special comment:

// Destructor
~ByteStream();

Now you have seen 90% of the magic. By using a slightly modified syntax for your comments, you can convert them into special comments that Doxygen can read. Furthermore, by using a few keywords, you can advance the formatting. In addition, Doxygen has some special features, which I will highlight in the following section.

Features

Most of the work is already done via your regular commenting on the source code. But with a few tweaks, you can easily enhance the output of Doxygen.

(Video) Code documentation with Doxygen, Graphviz, UMLet, HTML Help | Learn with George

Markdown

For advanced formatting, Doxygen supports Markdown syntax and HTML commands. There is a Markdown cheat sheet available in the download section of opensource.com.

Mainpage

Aside from your customized header, you will get a mostly empty page when you open html/index.html. You can add some meaningful content to this empty space by using specific keywords. Because the main page is usually not dedicated to a particular source code file, you can add an ordinary text file containing the content for the main page into the root of your project. You can see this in the example on GitHub. The comments in there produce the following output:

Document your source code with Doxygen on Linux (5)

Image by:

(Stephan Avenwedde, CC BY-SA 4.0)

Automatic link generation

As noted above, Doxygen automatically figures out when you are referring to an existing part of the code and creates a link to the related documentation. Be aware that automatic link creation only works if the part you refer to is documented as well.

More information can be found in the official documentation, under Automatic link generation.

Groups

The ByteStream class has overloaded stream operators for writing (<<) and reading (>>). In the class overview in the Special comments section above, you can see that the operator declarations are grouped as Writing and Reading. These groups are defined and named in the ByteStream header file.

Grouping is done using a special syntax: You start a group with @{ and end it with }@. All members inside those marks belong to this group. In the header ByteStream.h it is implemented as follows:

/** @name Writing
* Operators for writing to the stream
* @{
*/

(...)

/** @}
* @name Reading
* Operators for reading from the stream
* @{
*/

(...)

/** @} */

You can find more information about grouping in the Doxygen documentation, under Grouping.

LLVM Support

If you are building with Clang, you can apply the flag -Wdocumentation to the build process to let Clang check your special comments. You can find more information about this feature in the LLVM Users Manual or in Dmitri Gribenko's presentation, both on the Clang website.

Where Doxygen is used

Doxygen was first released in 1997, so it has been already around for some years. Despite its age, many projects use Doxygen to create their documentation. Some examples are NASA's F Prime flight software framework, the image processing library OpenCV, and the package manager RPM. You can also find the Doxygen syntax in other areas, like in the documentation standards of the content management platform Drupal.

A caveat: One drawback of using Doxygen is that it outputs HTML documentation with the look and feel of web pages from the nineties. It is also hard to depict the architecture of meta and template programming using Doxygen. For those cases, you would probably choose Sphinx over Doxygen. Download the Doxygen cheat sheet now.

Document your source code with Doxygen on Linux (6)This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.

(Video) Using Doxygen to document computing projects

FAQs

How do I document my code using doxygen? ›

In order to generate doxygen based documentation, you need to follow four steps:
  1. have the doxygen executable installed on your computer (this is already done on our DESY machines)
  2. document your code.
  3. create a configuration file.
  4. run doxygen to create the documentation (HTML or LaTeX based).
30 Apr 2019

How install doxygen Linux? ›

Compilation is now done by performing the following steps:
  1. Unpack the archive, unless you already have done that: gunzip doxygen-$VERSION.src.tar.gz # uncompress the archive tar xf doxygen-$VERSION.src.tar # unpack it.
  2. Create a build directory (for instance inside the source tree) cd doxygen-$VERSION mkdir build cd build.

Is doxygen open source? ›

Doxygen is free software, released under the terms of the GNU General Public License version 2 (GPLv2).

What is Doxygen in Linux? ›

Doxygen is a documentation system for C++, C, Java, Objective-C, IDL (Corba and Microsoft flavors) and to some extent PHP, C#, and D. You can use doxygen in a number of ways: Tag. Description.

How do I document my code? ›

Here are three concrete steps you can take to write good documentation before it's too late.
  1. Start with accurate notes. As you work out ideas in code, ensure you don't soon forget important details by starting with accurate notes. ...
  2. Explain decisions in long form. ...
  3. Don't neglect prerequisite knowledge.
21 Dec 2020

How use Doxygen command line? ›

Running from Visual Studio
  1. From the Tools menu select External Tools...
  2. Click the Add button to create a new external tool configuration.
  3. For the Title enter “Doxygen”
  4. For the Command enter the path to the Doxygen executable. ( ...
  5. For the Arguments enter the name of your configuration file.

What is Doxygen code? ›

Doxygen is the de facto standard tool for generating documentation from annotated C++ sources, but it also supports other popular programming languages such as C, Objective-C, C#, PHP, Java, Python, IDL (Corba, Microsoft, and UNO/OpenOffice flavors), Fortran, and to some extent D.

How do I link a file in Doxygen? ›

1 Answer
  1. You can include blocks of source code using the \include command. From the Doxygen manual: \include <file-name> ...
  2. Also, from this page. Links to files. All words that contain a dot (.) ...
  3. and finally, from the Doxygen FAQ: Doxygen automatically generates a link to the class MyClass somewhere in the running text.
12 Jan 2012

Do I need Doxygen? ›

As already explained, Doxygen is a tool that helps in writing reference documentation for different programming language such as Java, C, C++, C#, IDL, D etc. updating of the old configuration file, etc.

What is Doxygen Ubuntu? ›

Doxygen is the de facto regular tool for generating documentation from annotated C++ sources, however, it additionally supports different wellknown programming languages akin to C, objective-C, C#, Hypertext Preprocessor, Java, Python, IDL (Corba, Microsoft, and UNO/OpenOffice flavors), Fortran, VHDL and Tcl.

How long does Doxygen take? ›

Doxygen takes about 12 hours to run on our code base. This is primarily because there is a lot of code to process (~1.5M lines).

Can we use doxygen for Python? ›

Doxygen: It is not the tool of choice for most Python projects. But if you have to deal with other related projects written in C or C++ it could make sense. For this you can improve the integration between Doxygen and Python using doxypypy. Sphinx: The defacto tool for documenting a Python project.

How do I view doxygen documents? ›

Then, you simply run Doxygen, which generates an html folder. Now you go to that folder and click on the index. html file. The documentation for your code is now in an easy to read html file.

How do I create a doxygen comment? ›

Once specified, you can generate the comment stub by typing the respective “///” or “/**” above a function, or by using the (Ctrl+/) shortcut. To get started, you can have Visual Studio generate an . editorconfig file for you based on your existing setting for documentation by using the “Generate .

How do I create a doxygen PDF? ›

The generated file will be refman. pdf unless it's configured otherwise.
  1. Configure Doxygen for LaTeX output. GENERATE_LATEX = YES LATEX_OUTPUT = latex OUTPUT_DIRECTORY =
  2. Set up all your images for LaTeX output. ...
  3. Run Doxygen.
  4. Run {OUTPUT_DIRECTORY}\{LATEX_OUTPUT}\make. ...
  5. Open {OUTPUT_DIRECTORY}\{LATEX_OUTPUT}\refman.

How do I download doxygen? ›

All releases of doxygen can be found at https://sourceforge.net/projects/doxygen/files/.

How do you create a class diagram with doxygen? ›

Doxygen uses the "dot" tool to generate the following graphs: A graphical representation of the class hierarchy will be drawn, along with the textual one.
...
have the following meaning:
  1. A white box indicates a class. ...
  2. A solid arrow indicates public inheritance.
  3. A dashed arrow indicates protected inheritance.

What is good documentation for code? ›

Good Documentation Comes in Many Forms

Documentation is anything you write in addition to your code to help someone else understand how it works. You might not think of it this way, but a good example of code documentation is a README file. A good example of basic documentation is the Express. js README file.

What does it mean to document your code? ›

Code documentation is text that accompanies software code to explain what your code is doing, why it's written the way it is, and/or how to use it. There are two main categories of documentation: documentation inside the code and supporting documentation about the code.

Should I document my code? ›

Why Developers Should Write Documentation. Developers should write documentation because it makes it easier for both you and your coworkers to use your code. Well-written code is easy to read and understand. Documented code, on the other hand, is a gift to everyone—even to the coder that created it.

Should doxygen be in header or source? ›

The common sense tells that the Doxygen comment blocks have to be put in the header files where the classes, structs, enums, functions, declarations are. I agree that this is a sound argument for a libraries that are mean to be distributed without its source (only headers and libs with object code).

How do I host a doxygen document on GitHub? ›

The following are the steps added to the action:
  1. Checkout repository. - name: Checkout repository uses: actions/checkout@v2 with: submodules: "true" ...
  2. Install Doxygen. - name: Install Doxygen run: sudo apt-get install doxygen -y shell: bash. ...
  3. Generate Doxygen Documentation. ...
  4. Create . ...
  5. Deploy to GitHub Pages.
5 Dec 2021

How do I add a table in doxygen? ›

Doxygen supports two ways to put tables in the documentation. The easiest is to use the Markdown format as shown in Markdown Extensions section Tables. Although this format is easy to use and read, it is also rather limited. It supports only a simple grid of cells, while each cell is a single line of plain text.

How do I write C++ code documents? ›

  1. DM C++ Style Guide.
  2. Documenting C++ Code. Boilerplate for Header (.h) and Source (.cc) Files. Basic Format of Documentation Blocks. Documentation MUST be delimited in Javadoc style. Multi-line documentation delimiters SHOULD be on their own lines. Documentation MUST use Javadoc-style tags. ...
  3. Creating a compilation database.

Is read the docs free? ›

Our code is free and open source. Our company is bootstrapped and 100% user focused. Read the Docs Community hosts documentation for over 100,000 large and small open source projects, in almost every human and computer language.

What is doxygen configuration file? ›

A configuration file is a free-form ASCII text file with a structure that is similar to that of a Makefile , with the default name Doxyfile . It is parsed by doxygen . The file may contain tabs and newlines for formatting purposes.

How do I create a doxygen CHM file? ›

The short story: I can generate a CHM file with Doxygen.
...
3 Answers
  1. From windows explorer, Right click the generated . chm file and select properties.
  2. On the General tab, if you see an Unblock button, click it.
  3. Close the dialog and open the . chm file.
3 Jun 2015

How do I add a link in markdown? ›

Markdown syntax for a hyperlink is square brackets followed by parentheses. The square brackets hold the text, the parentheses hold the link.

Where do I put doxygen documentation? ›

For documenting a file this is even required since there is no such thing as "in front of a file". Doxygen allows you to put your documentation blocks practically anywhere (the exception is inside the body of a function or inside a normal C style comment block).

How exclude code from doxygen? ›

How can I make doxygen ignore some code fragment? The new and easiest way is to add one comment block with a \cond command at the start and one comment block with a \endcond command at the end of the piece of code that should be ignored.

How do I get doxygen on Ubuntu? ›

How to Install Doxygen on Ubuntu 20.04 LTS (Focal Fossa)
  1. Step 1: Prerequisites. a) You should have a running Ubuntu 20.04 LTS Server. ...
  2. Step 2: Update Your Server. ...
  3. Step 3: Install Doxygen. ...
  4. Step 4: Check Version. ...
  5. Step 5: Generate Documentation. ...
  6. Step 6: Check all the available options.
3 Aug 2022

What is doxygen Python? ›

Doxygen is a popular tool for generating documentation from annotated C++ sources; it also supports other popular programming languages such as C#, PHP, Java, and Python. Visit the Doxygen website to learn more about the system, and consult the Doxygen Manual for the full information.

Does doxygen work with Matlab? ›

This package allows you to extract automatically comments from your Matlab . m files using Doxygen to generate documentation. - all the documentation (html format) automatically generated by Doxygen from the two .

How does Python generate documentation code? ›

Generating Code Documentation with Pycco
  1. Project Setup.
  2. Generate some docs.
  3. Generated Docs.
  4. Make It Fancy.
  5. Auto-Generating Documentation for an Entire Project.
  6. Documentation for Non-Python Files.
  7. How About Project Level Documentation?
  8. Regeneration.

Does doxygen support markdown? ›

Doxygen can process files with Markdown formatting. For this to work the extension for such a file should be . md or . markdown (see EXTENSION_MAPPING if your Markdown files have a different extension, and use md as the name of the parser).

How long does doxygen take? ›

Doxygen takes about 12 hours to run on our code base. This is primarily because there is a lot of code to process (~1.5M lines).

How do I automate a PDF? ›

From the Settings panel, go to Auto PDF tab and check 'Enable Automation' option.

How do I run doxygen in terminal? ›

Running from Visual Studio
  1. From the Tools menu select External Tools...
  2. Click the Add button to create a new external tool configuration.
  3. For the Title enter “Doxygen”
  4. For the Command enter the path to the Doxygen executable. ( ...
  5. For the Arguments enter the name of your configuration file.

Why is doxygen used? ›

As already explained, Doxygen is a tool that helps in writing reference documentation for different programming language such as Java, C, C++, C#, IDL, D etc. updating of the old configuration file, etc.

How do I link a file in doxygen? ›

1 Answer
  1. You can include blocks of source code using the \include command. From the Doxygen manual: \include <file-name> ...
  2. Also, from this page. Links to files. All words that contain a dot (.) ...
  3. and finally, from the Doxygen FAQ: Doxygen automatically generates a link to the class MyClass somewhere in the running text.
12 Jan 2012

Should documentation be in the header or source file? ›

usage detailed) about a function should be documented in the source file where the function is implemented, rather than the header file where the function is declared.

How do you open a doxygen GUI? ›

  1. to start doxygen gui type in terminal type doxywizard . For diagram perhaps need also sudo apt-get install graphviz . – Peter Krauss. Nov 2, 2016 at 21:49.
  2. It confuses me every time I install a package via the CLI and it has some executable name which is not derivable from the package name. :( – schande. Oct 14 at 8:53.

Does doxygen work with Python? ›

Doxygen is the de facto standard tool for generating documentation from annotated C++ sources, but it also supports other popular programming languages such as C, Objective-C, C#, PHP, Java, Python, IDL (Corba, Microsoft, and UNO/OpenOffice flavors), Fortran, and to some extent D.

Videos

1. Introduction to Doxygen
(John's Basement)
2. Auto-Generated Python Documentation with Sphinx (See comments for update fix)
(avcourt)
3. How to Create (HTML and PDF) Software Documentation Using Doxygen
(Jaycon Systems)
4. Doxygen
(Christopher McMurrough)
5. Introduction to JavaDoc and Version Control
(Bob Laramee)
6. Qt C++ 04 Documentation with Doxygen
(Open Source Options)
Top Articles
Latest Posts
Article information

Author: Lakeisha Bayer VM

Last Updated: 11/10/2023

Views: 5876

Rating: 4.9 / 5 (69 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Lakeisha Bayer VM

Birthday: 1997-10-17

Address: Suite 835 34136 Adrian Mountains, Floydton, UT 81036

Phone: +3571527672278

Job: Manufacturing Agent

Hobby: Skimboarding, Photography, Roller skating, Knife making, Paintball, Embroidery, Gunsmithing

Introduction: My name is Lakeisha Bayer VM, I am a brainy, kind, enchanting, healthy, lovely, clean, witty person who loves writing and wants to share my knowledge and understanding with you.