简体   繁体   中英

Doxygen — How to link to a C++ file-scope global variable

I have some code that looks like this:

MyStruct.h

struct MyStruct
{
    // ...

    /**
      * \brief Initializes \link MYSTRUCT \endlink.
      */
    static void init();
};

/**
 * \var MYSTRUCT
 * \brief You must call MyStruct::init() before using this variable.
 */
extern MyStruct const * MYSTRUCT;

Question

I would like to have the Doxygen documentation on MyStruct::init link to the Doxygen documentation on MYSTRUCT . However, Doxygen can't resolve the link as I provide it. What do I need to do to make the link work?

NOTE: Doxygen v 1.8.4 on Windows 7

Here is the corrected example that should work. Note that I added a comment block with \\file (and removed the redundant \\var)

/** \file */

/** My struct documentation */
struct MyStruct
{
    // ...

    /**
     * \brief Initializes \link MYSTRUCT \endlink.
     */
    static void init();
};

/**
 * \brief You must call MyStruct::init() before using this variable.
 */
extern MyStruct const * MYSTRUCT;

If you don't want a page with global data, but want MYSTRUCT to appear as part of MyStruct's documentation you can use \\relates like so:

/** My struct documentation */
struct MyStruct
{
  // ...

  /**
   * \brief Initializes \link MYSTRUCT \endlink.
   */
  static void init();
};

/**
 * \brief You must call MyStruct::init() before using this variable.
 * \relates MyStruct
 */
extern MyStruct const * MYSTRUCT;

and you can use #MYSTRUCT as a short-hand notation for \\link MYSTRUCT \\endlink

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM