C++11引入了dynamic_cast、type_info等RTTI(Run-Time Type Identification)工具,但C++在Reflection编程方面功能依旧有限。在社区上,RTTR则提供了一套C++编写的反射库,补充了C++在Reflection方面的缺陷。
零、环境
操作系统 | Windows 11 |
Visual Studio | Visual Studio Community 2022 |
CMake | CMake 3.24.2 |
Doxygen | Doxygen-1.9.8 |
一、下载源码
从GitHub拉取RTTR代码:
git clone https://github.com/rttrorg/rttr.git
二、编译
按照下表配置CMake,并完成构建与生成,
Where is the source code | Windows 11 |
Where to build the binaries | Visual Studio Community 2022 |
CMAKE_INSTALL_PREFIX | CMake 3.24.2 |
打开rttr.sln,构建"ALL_BUILD"完成RTTR编译;构建"INSTALL"完成RTTR安装。
网络资料
RTTRhttps://www.rttr.org/QMetaObjecthttps://doc.qt.io/qt-5/qmetaobject.html