2012-10-01 59 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