我一直在尝试使用Doxygen的,但收效甚微来记录我的C++项目:Doxygen的以失败识别某些宏,因此整个功能误解,大部分时间,即使他们有特殊的注释块,不产生文档.例证:
/**
* \def __MYLIB_FUNCTION_ATTRIBUTE(...)
* \brief Some brief comment
* \details Detailed doc
* \sa Some valid references
*/
#define __MYLIB_FUNCTION_ATTRIBUTE(...) __attribute__(__VA_ARGS__)
/**
* \def IN
* \brief Tag for input arguments to a function
* \details Blah...
* \sa OUT
*/
#define IN
/**
* \def OUT
* \brief Tag for output arguments to a function
* \details Blah...
* \sa IN
*/
#define OUT
class MyClass {
public:
/**
* \fn MyClass()
* \brief Constructor for MyClass
* \details Hi!
*/
__MYLIB_FUNCTION_ATTRIBUTE(__always_inline__)
MyClass() {
}
/**
* \fn const char *doNothing(const char *s IN)
* \brief A weird function
* \details Some very weird doc
* \param[in] s No good parameter
*/
const char* __SXC_FUNCTION_ATTRIBUTE(__const__) doNothing(const char *s IN) {
return s;
}
};
Run Code Online (Sandbox Code Playgroud)
为上述类生成的文档始终缺少描述,doNothing
并被IN
解释为函数!我在这里做错了吗?
两件事情:
1) Doxygen 解析器不会“看到” doNothing 中的“IN”(因为它在预处理阶段被删除),因此 \fn 不应包含它:const char* doNothing(const char* s)
。顺便说一句,这个 \fn 不是必需的:如果注释紧接在记录的实体之前,Doxygen 会自动关联该注释。
2)我不知道 __SXC_FUNCTION_ATTRIBUTE 扩展成什么,但是,如果它与 __MYLIB_FUNCTION_ATTRIBUTE 类似,它可能会让 Doxygen 感到困惑。作为解决方法,您可以在 Doxygen 配置文件的 PREDEFINED 部分中将这些宏定义为空,或者有条件地在源中定义它们,如下所示:
#ifdef DOXYGEN
// Doxygen does not grok the normal definition of this
#define __MYLIB_FUNCTION_ATTRIBUTE(...)
#else
#define __MYLIB_FUNCTION_ATTRIBUTE(...) __attribute__(__VA_ARGS__)
#endif
Run Code Online (Sandbox Code Playgroud)
并将 PREDEFINED = DOXYGEN 放入您的配置文件中。