(一)简介
Doxygen可以从C++, java等源代码中提取消息来生成帮助文档, API资料等。Doxygen辅于Graphviz的 dot小工具,则可以自动生成UML的类图等。
(二)quick start
以下,是在windows平台下的demo介绍。linux下,步骤类同。
示例
1)下载Doxygen
http://www.stack.nl/~dimitri/doxygen/index.html
doxyen主页
下载Graphviz(如果你不需要生成UML图的话,就不是必需的。不过,偶建议大家也下载一下吧)
http://www.graphviz.org/
Graphviz - Graph Visualization Software
在ubuntu下直接sudo apt-get install doxygen doxygen-doc graphviz
即可安装好这两个软件。此时,doxygen的文档就可以在/usr/share/doc下找到
2)安装这两个软件
假设分别安装在C:\Program Files\doxygen和C:\Program Files\ATT\Graphviz
3)写一个示例小程序try.cpp
/**
* try.cpp
* a simple demo for doxygen
*/
#include <stdio.h>
/**
* the base class Shape
*/
class Shape{
public :
/**
* the constructor
*/
Shape(){}
/**
* the destructor
*/
~Shape(){}
/**
* the Draw method
*/
virtual void Draw(){ printf("shape..\n");}
};
/**
* the concrete class Rectangle
*/
class Rectangle:public Shape{
public :
/**
* the constructor
* @param w is the width
* @param h is the height
*/
Rectangle(int w, int h)
{
width=w;
height=h;
}
/**
* the destructor
*/
~Rectangle(){}
/**
* the Draw method
*/
void Draw()
{
printf("Rectangle, width:%d, height:%d\n", width, height);
}
private :
int width,height;
};
int main()
{
Rectangle* obj =new Rectangle(10, 3);
obj->Draw();
return 1;
}
用Doxygen工具,即可自动生成api文档
4)将try.cpp复制到doxygen的安装路径相应位置下,即c:\Program Files\doxygen\bin
5)运行doxygen -g
它将生成一下Doxfile文件
6)按需要修改Doxfile
常用的参数有:PROJECT_NAME(项目的名称),PROJECT_NUMBER(项目的版本号),OUTPUT_DIRECTORY(文档输出的 目录),INPUT(源代码的输入目录)。默认下,会生成LATEX文档,一般没什么用。所以,我经常是将GENERATE_LATEX设为NO。如果, 你需要通过Graphviz的dot工具去生成UML图的话,你将HAVE_DOT设为YES,并设置DOT_PATH属性和DOTFILE_DIRS属 性。我这两项的设置分别是 "C:\Program Files\ATT\Graphviz\bin\dot.exe", "C:\Program Files\ATT\Graphviz\bin"。
7)运行doxygen Doxfile
这样就会生成一个html文件夹,打开该文件夹下的index.html即可。
(三)配置文件
通过doxygen -s -g命令可以生成一个doxygen模板。doxygen -g命令也可以生成一个doxygen模板。不同的是,它有对各个属性的介绍信息。
我最经常改的属性有:PROJECT_NAME(项目名),OUTPUT_DIRECTORY(文档的输出目录)、INPUT(源代码输入目录)、 RECURSIVE(是否递归目录来生成文档)、GENERATE_LATEX(是否生成latex文档)。如果要联合使用dot工具,那我们就需要改如 下三个属性:HAVE_DOT,DOT_PATH和DOTFILE_DIRS。
[相关资料]
http://www.cppblog.com/richardzeng/archive/2006/03/24/4508.html
Doxygen 源代码文档自动生成器的使用笔记
http://blog.csdn.net/SeSe/archive/2004/10/11/132226.aspx
强大的代码编档工具—Doxygen
http://www.linuxsir.org/bbs/showthread.php?p=1202525
有没有根据源代码生成类图的小工具?
http://blog.xmli.cn/read.php/97.htm
Doxygen 下载试用
http://www.yuanma.org/data/2006/0726/article_1245.htm
开源的自动化文档生成工具DoxyGen(转载)
http://www.wujianrong.com/mt-tb.cgi/5753