How to generate documentation from source code in Linux

If you are an open-source developer and want to release your project to the public, you may consider publishing source-code documentation for the project. In cases where you are trying to read source code written by others, it will also be helpful if you can get a "bird-eye" view of the otherwise cryptic source code.

In Linux, doxygen is the de facto standard tool for automatically generating cross-reference documentation from annotated source code. It supports major programming languages including C/C++, Objective-C, C#, PHP, Java and Python.

Using doxygen, you can auto-generate API reference documentation of source code, in HTML or Latex format. You can also visualize class dependency and the relationship between different source files.

In this tutorial, I will explain how to automatically generate documentation from source code in Linux by using doxygen.

Install Doxygen on Linux

To install doxygen on Ubuntu, Mint or Debian:

$ sudo apt-get install doxygen
$ sudo apt-get install graphviz

To install doxygen on CentOS, Fedora or RHEL:

$ sudo yum install doxygen
$ sudo yum install graphviz

Generate Documentation from Source code with Doxygen

To generate documentation of source code, proceed as follows.

First, generate a project-specific doxygen configuration file:

$ doxygen -g my_proj.conf

The above command will generate a template configuration file for a particular project.

Among others, you can edit the following options in the configuration file.

# document all entities in the project.
EXTRACT_ALL            = YES

# document all static members of a file.

# specify the root directory that contains the project's source files.
INPUT                  = /home/xmodulo/source

# search sub-directories for all source files.
RECURSIVE              = YES

# include the body of functions and classes in the documentation.

# generate visualization graph by using dot program (part of graphviz package).
HAVE_DOT               = YES

Now go ahead and run doxygen with the configuration file.

$ doxygen my_proj.conf

Documentations are generated in both HTML and Latex formats, and stored in ./html and ./latex directories respectively.

To browse the HTML-formatted documentation, run the following.

$ cd html
$ firefox index.html

Doxygen Documentation Screenshots

Here are several screenshots for doxygen outputs.

This shows a list of header files that are automatically categorized by topics.

This shows a list of classes, structs, unions and interfaces with descriptions.

This shows a source code browser listing all source files recursively in sub-directories.

If you click on a particular source file, you will see a page which shows dependency graph for the file, as well as documentation for all defined functions.

This shows a detailed view of function/macro definitions. Below the figure is shown the actual source code snippet that corresponds to this documented portion.

Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

One thought on “How to generate documentation from source code in Linux

Leave a comment

Your email address will not be published. Required fields are marked *