2012-10-01 52 views
0

我正在尝试使用XCppRefl库来实现C++中的反射。 http://www.extreme.indiana.edu/reflcpp/。我可以在linux中成功安装这个库,并运行与库的源代码一起提供的测试。使用XCppRefl代码不起作用

这里是我写的代码 -

#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; 
} 

这似乎编译就好了 - 当我执行的可执行文件(a.out)

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

不过,我得到核心转储

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) 

有没有人曾经使用过这个库?请帮忙。

回答

0

您必须将main.o链接到libreflcpp.a。编译后使用这个:

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