參考文章:
http://www.fmddlmyy.cn/text21.html
http://www.cnblogs.com/duguguiyu/archive/2008/06/29/1231852.html ---入門介紹
https://www.ibm.com/developerworks/cn/aix/library/au-aix-graphviz/index.html
1 Doxygen簡介
1.1 What to do?
使用Doxygen生成文檔,主要是兩件事:
- 寫一個配置文件(Doxyfile),一般用Doxywizard生成后,再手工修改[不建議使用,不直觀,比較麻煩]。或者可以用輔助的GUI工具幫助書寫,你只需要改幾個選項,點幾下按鈕就可以了(在下面有介紹)。
- 按照Doxygen的約定,將代碼“文檔化”。
如果已經有配置文件(Doxyfile),執行命令:doxygen Doxyfile,
就會輸入文件、輸出目錄、參數等都是在Doxyfile中配置好的,在/doc/html/index.html中查看。
1.2 What you want?
Doxygen的輸出格式主要有HTML、LATEX、RTF等:
- Doxygen在輸出HTML文檔時,可以自動准備用於制作CHM的項目文件(.hhp)、目錄文件(.hhc)和索引文件(.hhk)。用HTML Help Workshop中的CHM編譯器(hhc.exe)編譯后生成CHM文件。
- Doxygen在輸出LATEX文檔的同時准備了轉換到pdf格式的makefile。只要系統安裝了合適的TEX工具,就可以從LATEX文檔生成pdf文檔。
- Doxygen輸出的RTF格式,已經針對Word作了優化,可以較好地轉換到Word文檔。
1.3 install
如果你電腦里可能還沒有doxygen,我們先來安裝一下:
sudo apt-get install doxygen doxygen-gui //就是上面提到的GUI,不用再寫Doxyfile,用GUI工具。
[sudo] password for wj: Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: libopencc1 Use 'apt-get autoremove' to remove it. Suggested packages: doxygen-doc The following NEW packages will be installed: doxygen-gui 0 upgraded, 1 newly installed, 0 to remove and 354 not upgraded. Need to get 279 kB of archives. After this operation, 671 kB of additional disk space will be used. Get:1 http://cn.archive.ubuntu.com/ubuntu/ trusty/universe doxygen-gui amd64 1.8.6-2 [279 kB] Fetched 279 kB in 0s (291 kB/s) Selecting previously unselected package doxygen-gui. (Reading database ... 264559 files and directories currently installed.) Preparing to unpack .../doxygen-gui_1.8.6-2_amd64.deb ... Unpacking doxygen-gui (1.8.6-2) ... Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Setting up doxygen-gui (1.8.6-2) ...
總之,主要是doxygen本體和它的gui模塊。如果你不確定,請用這個查一下。
j@wj-Inspiron-5437:~$ apt-cache search doxygen-gui
doxygen-gui - GUI configuration tool for doxygen
拿以難讀著稱的lsd-slam舉個例子。
[1]首先,建個文件夾,把lsd-slam的代碼拷下來:
git clone https://github.com/tum-vision/lsd_slam.git
[2]在該文件夾下開一個doc文件夾,把一會兒生成的文檔放里頭:
mkdir doc;
cd doc
[3]輸入doxywizard調出gui面板。
wj@wj-Inspiron-5437:~/Downloads/lsd_slam/doc$ doxywizard
然后就會出一個面板啦...
step1---Wizard
1.“Project”:
[1]Doxygen工作目錄填寫,即doc所在路徑。
[2]Project name那些東西隨意,可以不設。
[3]重要的是源代碼目錄source code directory,請把它設到lsd_slam_core/src下,並鈎上Scan recursively,表明我們要掃描子文件夾。
[4]輸出文件夾設成當前目錄./即可,也就是/home/wj/Downloads/lsd_slam/doc
2.進入下一個版塊“Mode”,點“Next”。選擇All Entities,可以輸出相對完整的功能,是否包含源代碼看自身情況;在下面選擇好自己的語言,既然咱們用c++,保持默認的就可以了。
3.“Output”:如果你需要輸出chm格式,勾選chm,沒有要求的話html就可以了
4.Diagrams:選擇使用GraphViz包,來輸出UML,GraphViz包可以幫助建立一些樹狀視圖。
step2---Expert
需要首選確定你所輸出的語言,很重要的是INPUT_ENCODING項,如果使用的為微軟默認字符集請填寫GBK,不然目錄亂碼,當前選擇UTF-8,輸出語言選擇的是Chinese.
......以上的配置基本情況下就可以啦,剩下的就不在這里贅述了,感興趣可以參考:http://www.cnblogs.com/chenyang920/p/5732643.html
step3---Run
准備工作完成啦!切到Run,點“Run doxygen",等文檔生成完。然后點“show html output",就可以在瀏覽器里看到文檔啦。如果你下一次想直接看,直接打開doc/html/index.html就可以了!
看這個比看源代碼效果更高哦!
附:原理圖
2 Graphviz簡介
Graphviz是一個圖形可視化軟件。Doxygen使用Graphviz生成各種圖形,例如類的繼承關系圖、合作圖,頭文件包含關系圖等。適用於大多數平台的二進制文件可以在 Graphviz 官網 上找到,AIX 二進制文件可以在 perzl.org 上找到。Doxygen使用了Graphviz的布局引擎dot,所以在文檔中將其稱作dot。
install
$ sudo apt-get install graphviz graphviz-doc //這樣會安裝dot語言的執行文件,執行文件路徑在/usr/bin/dot
可以來個測試:
[1]自己創建一個test.dot (更多例子可以參見官方文檔)---dot
digraph G { subgraph cluster0 { node[style=filled, color=white]; style=filled; color=lightgrey; a0->a1->a2->a3; label="process #1"; } subgraph cluster1 { node[style=filled]; color=blue; b0->b1->b2->b3; label="process #2"; } start->a0; start->b0; a1->b3; b2->a3; a3->end; b3->end; start[shape=Mdiamond]; end[shape=Msquare]; }
[2]執行命令:
$ dot -Tpng test.dot -o test.png //都是用來生成圖片,選擇其中一個即可。
$ dot -Tsvg test.dot -o test.svg
$ dot -Tpdf test.dot -o test.pdf
[3]結果: