使用 XCppRefl 的代码不起作用

Code with XCppRefl does not work

本文关键字:不起作用 代码 XCppRefl 使用      更新时间:2023-10-16

我正在尝试使用XCppRefl lib来实现c ++中的反射 http://www.extreme.indiana.edu/reflcpp/。我可以在 linux 中成功安装这个库,并运行使用该库源代码给出的测试。

这是我写的代码——

#include <iostream>
using namespace std;
#include <reflcpp/ClassType_tmpl.hpp>
#include <reflcpp/BoundClassType_tmpl.hpp>
#include <reflcpp/Exceptions.hpp>
using namespace reflcpp;
#include "Complex.h"

int main()
{
    //ClassType ct = ClassType::getClass( string("Complex") );
    ////PtrHolder_smptr_t obj = ct.createInstance();
    //assert(ct.name() == "B");
    Complex x;
    int ret;
    Complex a;
    ClassType c = ClassType::getClass( string("Complex") );
    //cout<<"name :: "<<c.name()<<endl;
}

似乎编译得很好——

   $ g++ -g -I /usr/local/include/reflcpp-0.2/ -L /usr/local/include/reflcpp-0.2/ -lreflcpp  main.cpp  

但是,当我执行可执行文件(a.out)时,我得到一个核心转储

a.out: Type.cpp:87: static const reflcpp::Type_body* reflcpp::Type_body::getType(const std::string&): Assertion `s_class_name_map' failed.
Aborted (core dumped)

以前有人用过这个库吗?请帮忙。

你必须

将你的main.o链接到libreflcpp.a。 编译后使用以下命令:

g++ -p -pg -o"project_name"  ./A.o ./A_reflection.o ./main.o  /usr/local/lib/libreflcpp.a