有没有一些工具可以在Linux中检查C++代码并生成类层次结构/依赖关系图?
我被给予了这个庞大的C++文件集合,这样一个工具对于帮助我理解源代码将是无价之宝。我对理解它感到有些混乱。
尝试使用doxygen,它可能已经随着您的发行版一起安装了。
您可能需要GraphViz来生成图形。这里有一个简单的示例和输出结果。
这是由doxygen生成的legend文件的更复杂的例子:
代码(注意:如果您只想生成图形,则不需要注释):
/*! Invisible class because of truncation */
class Invisible { };
/*! Truncated class, inheritance relation is hidden */
class Truncated : public Invisible { };
/* Class not documented with doxygen comments */
class Undocumented { };
/*! Class that is inherited using public inheritance */
class PublicBase : public Truncated { };
/*! A template class */
template<class T> class Templ { };
/*! Class that is inherited using protected inheritance */
class ProtectedBase { };
/*! Class that is inherited using private inheritance */
class PrivateBase { };
/*! Class that is used by the Inherited class */
class Used { };
/*! Super class that inherits a number of other classes */
class Inherited : public PublicBase,
protected ProtectedBase,
private PrivateBase,
public Undocumented,
public Templ<int>
{
private:
Used *m_usedClass;
};
结果:
您不需要对代码进行注释以生成这些图表。第一个示例根本没有注释。第二个示例有一个类没有Doxygen样式的注释。只需设置适当的参数(至少应将EXTRACT_ALL = YES
设置成为必要条件,我无法记得是否还需要其他设置)。
cpp-depenencies
。cpp_dependency_graph
的工具,能够以 dot
、d3.js
或 JSON 格式生成组件/包含依赖关系图。d3.js
可视化示例。
cpp_dependency_graph
的作者。我建议你们尝试使用Source Navigator
一个适用于C/C++/Fortran/Java/Tcl/PHP/Python的集成开发环境(IDE)
Windows: https://sourcenav.sourceforge.net/
Linux(和Mac?):http://chenweixiang.github.io/2019/09/09/source-navigator-ng.html#install-source-navigator-ng-4-5-on-linuxmint
它有点过时,但长期以来一直是一个有用的工具。 已经有一段时间没有更新了(约2014年),所以在较新的C++14(+)功能中可能会出现困惑。据推测,也存在一些C++11的问题。 但对于显示相当复杂的类层次结构、包含依赖关系调查和简单的代码导航而言,它已经足够(前提是它不会在某些复杂的代码结构上崩溃)。
值得注意的是,过去还有源导航扩展 - 基本上是同样的东西,但你可以打开多个独立的窗口。
这是源代码: https://github.com/rogerz/sourcenavigatorSource Trail是一个易于使用的工具,在我的使用经验中,它具有直观的图形用户界面,帮助您探索语言元素与其他相关元素之间的关系。在我的MacOS上它运行得非常好。 截至2021年9月,该工具已不再开发,但代码库仍然可用。