# CCodeParse **Repository Path**: fatcat2018/ccode-parse ## Basic Information - **Project Name**: CCodeParse - **Description**: 基于libclang和Graphviz实现的C++代码解析并绘制调用链路图。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-13 - **Last Updated**: 2025-11-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 基于libclang实现C++代码链路解析 ## 一、`libclang`的安装 ### 1.1 Window环境下的安装 下载[LLVM for Windows](https://github.com/llvm/llvm-project/releases),本文档我们以`LLVM 21.1.4`版本为例,如下图所示: ![局部截取_20251113_113228](assets/局部截取_20251113_113228-20251113113233-nnltz4y.png) 下载完成后,双击安装。除下图所示位置需要修改外,其余步骤一路下一步! ![LLVM-21.1.4-win64.exe_20251113_113710](assets/LLVM-21.1.4-win64.exe_20251113_113710-20251113113754-6cnrp2c.png) 安装`完成`如图所示,点击完成。 ![LLVM-21.1.4-win64.exe_20251113_114153](assets/LLVM-21.1.4-win64.exe_20251113_114153-20251113114214-xwdfxss.png) 检查是否安装成功,默认安装路径:`C:\Program Files\LLVM\` ![局部截取_20251113_114425](assets/局部截取_20251113_114425-20251113114430-ook0e4o.png) 确认`libclang.dll`和头文件存在: ```shell C:\Program Files\LLVM\bin\libclang.dll # 头文件 C:\Program Files\LLVM\include\clang-c\ ``` ## 二、Graphviz的安装 ### 2.1 Windows环境下的安装 下载[Graphviz](https://graphviz.org/download/#windows),本文档我们以`graphviz-14.0.2`版本为例,如下图所示: ![局部截取_20251113_145157](assets/局部截取_20251113_145157-20251113145201-4zgtqpl.png) 下载完成后,双击安装。除下图所示位置需要修改外,其余步骤一路下一步! ![windows_10_cmake_Release_graphviz-install-14.0.2-win64.exe_20251113_151435](assets/windows_10_cmake_Release_graphviz-install-14.0.2-win64.exe_20251113_151435-20251113151453-i0wzozp.png) ## 三、Python实现 ### 1、使用Python虚拟环境创建工程 本Demo基于`Python 3.13` ![局部截取_20251113_151905](assets/局部截取_20251113_151905-20251113151914-8or8cop.png) ### 2、激活虚拟环境,并使用`pip`安装依赖 - 安装`libclang` ```log (.venv) PS E:\workspace\CCodeParse> pip install libclang Collecting libclang Obtaining dependency information for libclang from https://files.pythonhosted.org/packages/0b/2d/3f480b1e1d31eb3d6de5e3ef641954e5c67430d5ac93b7fa7e07589576c7/libclang-18.1.1-py2.py3-none-win_amd64.whl.metadata Downloading libclang-18.1.1-py2.py3-none-win_amd64.whl.metadata (5.3 kB) Downloading libclang-18.1.1-py2.py3-none-win_amd64.whl (26.4 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 26.4/26.4 MB 4.2 MB/s eta 0:00:00 Installing collected packages: libclang Successfully installed libclang-18.1.1 [notice] A new release of pip is available: 23.2.1 -> 25.3 [notice] To update, run: python.exe -m pip install --upgrade pip (.venv) PS E:\workspace\CCodeParse> ``` - 安装`flask` ```log (.venv) PS E:\workspace\CCodeParse> pip install flask Collecting flask Obtaining dependency information for flask from https://files.pythonhosted.org/packages/ec/f9/7f9263c5695f4bd0023734af91bedb2ff8209e8de6ead162f35d8dc762fd/flask-3.1.2-py3-none-any.whl.metadata Using cached flask-3.1.2-py3-none-any.whl.metadata (3.2 kB) Requirement already satisfied: blinker>=1.9.0 in e:\workspace\ccodeparse\.venv\lib\site-packages (from flask) (1.9.0) Requirement already satisfied: click>=8.1.3 in e:\workspace\ccodeparse\.venv\lib\site-packages (from flask) (8.3.0) Requirement already satisfied: itsdangerous>=2.2.0 in e:\workspace\ccodeparse\.venv\lib\site-packages (from flask) (2.2.0) Requirement already satisfied: jinja2>=3.1.2 in e:\workspace\ccodeparse\.venv\lib\site-packages (from flask) (3.1.6) Requirement already satisfied: markupsafe>=2.1.1 in e:\workspace\ccodeparse\.venv\lib\site-packages (from flask) (3.0.3) Requirement already satisfied: werkzeug>=3.1.0 in e:\workspace\ccodeparse\.venv\lib\site-packages (from flask) (3.1.3) Requirement already satisfied: colorama in e:\workspace\ccodeparse\.venv\lib\site-packages (from click>=8.1.3->flask) (0.4.6) Using cached flask-3.1.2-py3-none-any.whl (103 kB) Installing collected packages: flask Successfully installed flask-3.1.2 [notice] A new release of pip is available: 23.2.1 -> 25.3 [notice] To update, run: python.exe -m pip install --upgrade pip (.venv) PS E:\workspace\CCodeParse> ```