Getting started

The executable doxygen is the main program that parses the sources and generates the documentation. See section Doxygen usage for more detailed usage information.

The executable doxytag is only needed if you want to generate references to external documentation (i.e. documentation that was generated by Doxygen) for which you do not have the sources or to create a search index for the search engine. See section Doxytag usage for more detailed usage information.

The executable doxysearch is only needed if you want to use the search engine. See section Doxysearch usage for more detailed usage information.

Step 1: Creating a configuration file

Doxygen uses a configuration file to determine all of its settings. Each project should get its own configuration file. A project can consist of a single source file, but can also be an entire source tree that is recursively scanned.

To simplify the creation of a configuration file, Doxygen can create a template configuration file for you. To do this call doxygen with the -g option:

doxygen -g <config-file>
where <config-file> is the name of the configuration file. If you omit the file name, a file named Doxyfile will be created. If a file with the name <config-file> already exists, Doxygen will rename it to <config-file>.bak before generating the configuration template.

The configuration file has a format that is similar to that of a (simple) Makefile. It contains of a number of assignments (tags) of the form:

TAGNAME = VALUE or
TAGNAME = VALUE1 VALUE2 ...

You can probably leave the values of most tags to their default value.

The INPUT tag is the only tag for which you are required to provide a value. See section Configuration for more details about the configuration file. For a small project consisting of a few C and/or C++ source and header files, you can add the names of the files after the INPUT tag. If you have a larger project consisting of a source directory or tree this may become tiresome. In this case you should put the root directory or directories after the INPUT tag, and add one or more file patterns to the FILE_PATTERN tag. Only files that match one of the patterns will be parsed (if the patterns are omitted all files will be parsed). For recursive parsing of a source tree you must set the RECURSIVE tag to YES. To further finetune the list of files that is parsed the EXCLUDE and EXCLUDE_PATTERNS tags can be used.

If you start using Doxygen for an existing project (thus without any documentation that Doxygen is aware of), you can still get an idea of what the documented result would be. To do so, you must set the EXTRACT_ALL tag in the configuration file to YES. Then, Doxygen will pretend everything in your sources is documented. Please note that warnings of undocumented members will not be generated as long as EXTRACT_ALL is set to YES.

Step 2: Running doxygen

To generate the documentation you can now enter:

doxygen <config-file>

Doxygen will create a html, latex and/or man directory inside the output directory. As the names suggest the html directory contains the generated documentation in HTML format and the latex directory contains the generated documentation in format. Man pages are put in a man3 directory inside the man directory.

The default output directory is the directory in which doxygen is started. The directory to which the output is written can be changed using the OUTPUT_DIRECTORY , HTML_OUTPUT, LATEX_OUTPUT, and MAN_OUTPUT tags of the configuration file. If the output directory does not exist, doxygen will try to create it for you.

The generated HTML documentation can be viewed by pointing a HTML browser to the index.html file in the html directory. For the best results a browser that supports cascading style sheets (CSS) should be used (I'm currently using Netscape 4.0 to test the generated output).

The generated documentation must first be compiled by a compiler. (I use teTeX distribution version 0.4 that contains version 3.14159). To simplify the process of compiling the generated documentation, doxygen writes a Makefile into the latex directory. By typing make in the latex directory the dvi file refman.dvi will be generated. This file can then be viewed using xdvi or converted into a postscript file refman.ps by typing make ps (this requires dvips ). The Postscript file can be send to a postscript printer. If you do not have a postscript printer, you can try to use ghostscript to convert postscript into something your printer understands.

The generated man pages can be viewed using the man program. You do need to make sure the man directory is in the man path (see the MANPATH environment variable). Notice that there are some limitations to the capabilities of the man page format, so some information (like class diagrams, cross references and formulas) will be lost.

Step 3: Documenting the sources

Although documenting the source is presented as step 3, in a new project this should ofcourse be step 1. Here I assume you already have some code and you want Doxygen to generate a nice document describing the API and maybe the internals as well.

If the EXTRACT_ALL option is set to NO in the configuration file (the default), then doxygen will only generate documentation for documented members, files, classes and namespaces. So how do you document these? For members, classes and namespaces there are basicly two options:

  1. Place a special documentation block in front of the declaration or definition of the member, class or namespace. For file, class and namespace members it is also allowed to place the documention directly after the member. See section Special documentation blocks to learn more about special documentation blocks.
  2. Place a special documentation block somewhere else (another file or another location) and put a structural command in the documentation block. A structural command links a documentation block to a certain object that can be documented (e.g. a member, class, namespace or file). See section Structural commands to learn more about structural commands.
Files can only be documented using the second option. The text inside a special documentation block is parsed before it is written to the HTML and/or output files.

During parsing the following steps take place:

Special documentation blocks

The following types of special documentation blocks are supported by Doxygen:

Here is an example of a documented piece of C++ code using the Qt style:

//!  A test class. 
/*!
  A more elaborate class description.
*/

class Test
{
  public:

    //! An enum.
    /*! More detailed enum description. */
    enum TEnum { 
                 TVal1, /*!< Enum value TVal1. */  
                 TVal2, /*!< Enum value TVal2. */  
                 TVal3  /*!< Enum value TVal3. */  
               } 
         //! Enum pointer.
         /*! Details. */
         *enumPtr, 
         //! Enum variable.
         /*! Details. */
         enumVar;  
    
    //! A constructor.
    /*!
      A more elaborate description of the constructor.
    */
    Test();

    //! A destructor.
    /*!
      A more elaborate description of the destructor.
    */
   ~Test();
    
    //! A normal member taking two arguments and returning an integer value.
    /*!
      \param a an integer argument.
      \param s a constant chararcter pointer.
      \return The test results
      \sa Test(), ~Test(), testMeToo() and publicVar()
    */
    int testMe(int a,const char *s);
       
    //! A pure virtual member.
    /*!
      \sa testMe()
      \param c1 the first argument.
      \param c2 the second argument.
    */
    virtual void testMeToo(char c1,char c2) = 0;
   
    //! A public variable.
    /*!
      Details.
    */
    int publicVar;
       
    //! A function variable.
    /*!
      Details.
    */
    int (*handler)(int a,int b);
};

Click here for the corresponding HTML documentation that is generated by Doxygen.

The one-line comments should contain a brief description, whereas the multi-line comment blocks contain a more detailed description. The brief descriptions are included in the member overview of a class, namespace or file and are printed using a small italic font (this description can be omitted by setting BRIEF_MEMBER_DESC to NO in the config file). By default the brief descriptions are also the first sentence of the detailed description (this can be changed by setting the REPEAT_BRIEF tag to NO). Both the brief and the detailed descriptions are optional for the Qt style.

Here is the same piece of code, this time documented using the JavaDoc style:

/**
 *  A test class. A more elaborate class description.
 */

class Test
{
  public:

    /** 
     * An enum.
     * More detailed enum description.
     */

    enum TEnum { 
          TVal1, /**< enum value TVal1. */  
          TVal2, /**< enum value TVal2. */  
          TVal3  /**< enum value TVal3. */  
         } 
       *enumPtr, /**< enum pointer. Details. */
       enumVar;  /**< enum variable. Details. */
       
      /**
       * A constructor.
       * A more elaborate description of the constructor.
       */
      Test();

      /**
       * A destructor.
       * A more elaborate description of the destructor.
       */
     ~Test();
    
      /**
       * a normal member taking two arguments and returning an integer value.
       * @param a an integer argument.
       * @param s a constant chararcter pointer.
       * @see Test()
       * @see ~Test()
       * @see testMeToo()
       * @see publicVar()
       * @return The test results
       */
       int testMe(int a,const char *s);
       
      /**
       * A pure virtual member.
       * @see testMe()
       * @param c1 the first argument.
       * @param c2 the second argument.
       */
       virtual void testMeToo(char c1,char c2) = 0;
   
      /** 
       * a public variable.
       * Details.
       */
       int publicVar;
       
      /**
       * a function variable.
       * Details.
       */
       int (*handler)(int a,int b);
};

Click here for the corresponding HTML documentation that is generated by Doxygen.

Notice that the first sentence of the documentation (until the .) is treated as a brief description, whereas the documentation block as a whole forms the detailed description. The brief description is required for the JavaDoc style.

Unlike most other documentation systems, Doxygen also allows you to put the documentation of members (including global functions) in front of the definition. This way the documentation can be placed in the source file instead of the header file. This keeps the header file compact, and allows the implementer of the members more direct access to the documentation. As a compromise the brief description could be placed before the declaration and the detailed description before the member definition (assuming you use the Qt style comments).

Structural commands

So far we have assumed that the documentation blocks are always located in front of the declaration or definition of a file, class or namespace or in front of one of its members. Although this is often comfortable, it may sometimes be better to put the documentation somewhere else. For some types of documentation blocks (like file documentation) this is even required. 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), as long as you put a structural command inside the documentation block.

Structural commands (like all other commands) start with a backslash (\) followed by a command name and one or more parameters. For instance, if you want to document the class Test in the example above, you could have also put the following documentation block somewhere in the input that is read by Doxygen:

/*! \class Test
    \brief A test class.

    A more detailed class description.
*/

Here the special command \class is used to indicated that the comment block contains documentation for the class Test. Other structural commands are:

See section Special Commands for detailed information about these and other commands. Notice that the documentation block belonging to a file should always contain a structural command.

To document a member of a C++ class, you must also document the class itself. The same holds for namespaces. To document a C function, typedef, enum or preprocessor definition you must first document the file that contains it (usually this will be a header file, because that file contains the information that is exported to other source files).

Here is an example of a C header named structcmd.h that is documented using structural commands:

/*! \file structcmd.h
    \brief A Documented file.
    
    Details.
*/

/*! \def MAX(a,b)
    \brief A macro that returns the maximum of \a a and \a b.
   
    Details.
*/

/*! \var typedef unsigned int UINT32
    \brief A type definition for a .
    
    Details.
*/

/*! \var int errno
    \brief Contains the last error code.

    \warning Not thread safe!
*/

/*! \fn int open(const char *pathname,int flags)
    \brief Opens a file descriptor.

    \param pathname The name of the descriptor.
    \param flags Opening flags.
*/

/*! \fn int close(int fd)
    \brief Closes the file descriptor \a fd.
    \param fd The descriptor to close.
*/

/*! \fn size_t write(int fd,const char *buf, size_t count)
    \brief Writes \a count bytes from \a buf to the filedescriptor \a fd.
    \param fd The descriptor to write to.
    \param buf The data buffer to write.
    \param count The number of bytes to write.
*/

/*! \fn int read(int fd,char *buf,size_t count)
    \brief Read bytes from a file descriptor.
    \param fd The descriptor to read from.
    \param buf The buffer to read into.
    \param count The number of bytes to read.
*/

#define MAX(a,b) (((a)>(b))?(a):(b))
typedef unsigned int UINT32;
int errno;
int open(const char *,int);
int close(int);
size_t write(int,const char *, size_t);
int read(int,char *,size_t);
Click here for the corresponding HTML documentation that is generated by Doxygen.

Notice:
Because each comment block in the example above contains a structural command, all the comment blocks could be moved to another location or input file (the source file for instance), without affecting the generated documentation. The disadvantage of this approach is that prototypes are duplicated, so all changes have to be made twice!

Documenting compound members.

If you want to document the members of a file, struct, union, class, or enum and you want to put the documentation for these members inside the compound, it is sometimes desired to place the documentation block after the member instead of before. For this purpose Doxygen has the following additional comment blocks:

/*!< ... */
This block can be used to put a qt style documentation blocks after a member. The one line version look as follows:
//!< ...
There are also JavaDoc versions:
/**< ... */
and
///< ... 
Notice that these blocks have the same structure and meaning as the special comment blocks above only the < indicates that the member is located in front of the block instead of after the block.

Here is an example of a the use of these comment blocks:

/*! A test class */

class Test
{
  public:
    /** An enum type. 
     *  The documentation block cannot be put after the enum! 
     */
    enum EnumType
    {
      int EVal1,     /**< enum value 1 */
      int EVal2      /**< enum value 2 */
    };
    void member();   //!< a member function.
    
  protected:
    int value;       /*!< an integer value */
};
Click here for the corresponding HTML documentation that is generated by Doxygen.

Warning:
These blocks can only be used to document members. They cannot be used to document file classes, unions, structs and enums. Furthermore, the structural commands mentioned in the previous section are ignored inside these comment blocks.

Including formulas in the documentation

Doxygen allows you to put formulas in the output (this works only for the HTML and formats, not for the man page output). To be able to include formulas (as images) in the HTML documentation, you will also need to have the following tools installed

There are two ways to include formulas in the documentation.

  1. Using in-text formulas that appear in the running text. These formulas should be put between a pair of \f$ commands, so
      The distance between \f$(x_1,y_1)\f$ and \f$(x_2,y_2)\f$ is 
      \f$\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\f$.
    
    results in:

    The distance between and is .

  2. Unnumbered displayed formulas that are centered on a separate line. These formulas should be put between \f\[ and \f\] commands. An example:
      \f[
        |I_2|=\left| \int_{0}^T \psi(t) 
                 \left\{ 
                    u(a,t)-
                    \int_{\gamma(t)}^a 
                    \frac{d\theta}{k(\theta,t)}
                    \int_{a}^\theta c(\xi)u_t(\xi,t)\,d\xi
                 \right\} dt
              \right|
      \f]
    
    results in:

Formulas should be valid commands in 's math-mode.

Warning:
Currently, Doxygen is not very fault tolerant in recovering from typos in formulas. It may have to be necessary to remove the file formula.repository that is written in the html directory to a rid of an incorrect formula

More information

For a more elaborate example see the documentation of QdbtTabular . I hope that was clear. If not, please let me know, so I can improve this document. If you have problems take a look at the troubleshooting section.


Generated at Thu Sep 2 10:59:30 1999 by doxygen  written by Dimitri van Heesch, © 1997-1999