如何使用Doxygen为Fortran模块内的interface接口编写文档
Doxygen识别Fortran interface文档的解决方案
1. 调整Doxyfile配置
打开项目对应的Doxyfile配置文件,修改以下参数:
OPTIMIZE_FOR_FORTRAN = YES开启Fortran语法专项优化FORTRAN_ADD_INTERFACES = YES强制Doxygen扫描并解析interface块内容- 如果未开启
EXTRACT_ALL = YES,需要确保模块和接口都有显式文档注释,否则会被判定为私有成员忽略
2. 调整代码注释写法
原有注释仅需要微调位置和补充外层模块注释即可生效,调整后的完整代码如下:
!> \brief 测试用模块,包含阶乘计算接口 module test_mod implicit none !> \brief !> Return the factorial for a whole integer input. This is basically `Gamma( intNum + 1 )`. !> !> \param[in] positiveInteger : The input positive integer whose factorial must be computed. !> !> \return !> `factorial` : The factorial. interface pure function getFactorial(positiveInteger) result(factorial) use iso_fortran_env, only: IK => int32, RK => real64 implicit none integer(IK), intent(in) :: positiveInteger real(RK) :: factorial end function getFactorial end interface end module test_mod
核心调整点:
- 给外层
test_mod模块添加了基础文档注释,避免Doxygen跳过整个模块内容的解析 - 接口注释紧跟在
interface关键字的上一行,不要和interface块之间留空行
3. 验证效果
重新运行Doxygen生成文档,即可在模块的接口列表下看到getFactorial的完整文档说明。
内容的提问来源于stack exchange,提问作者Scientist
相关产品推荐
相关产品推荐

