C++ linker error after change in thrift file -


i think related c++ linker error thrift. made change thrift file , regenerated cpp & java classes. after change, started getting linker errors in cpp. here error

undefined symbols:

"com::xxxx::thrift::employee::savingsinfo::operator<(com::xxxx::thrift::employee::savingsinfo const&) const", referenced from: std::less::operator()(com::xxxx::thrift::employee::savingsinfo const&, com::xxxx::thrift::employee::savingsinfo const&) constin employee_types.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [thriftcppsamples] error 1

i added savingsinfo type thrift file, change made. give options mentioned in doc g++. gave -i/usr/local/include/thrift, -i/path-to-boost, -l/path-to-boost-lib, -lthrift. after change started getting above linker error. couldn't understand reason this. error points generated thrift. reason error?

this error "operator <", posting code relevant it. full code available 2 links provided @ end.

employee_types.h

class savingsinfo { public:     std::string name;     double amount;     bool operator == (const savingsinfo & rhs) const { /*...*/ }     bool operator != (const savingsinfo &rhs) const { return !(*this == rhs); }     bool operator < (const savingsinfo & ) const;     uint32_t read(::apache::thrift::protocol::tprotocol* iprot);     uint32_t write(::apache::thrift::protocol::tprotocol* oprot) const; };  class employeeinfo { public:     int32_t id;     std::string name;     double salary;     bool contract;     std::set<std::string>  dependents;     std::set<savingsinfo>  savings;     bool operator == (const employeeinfo & rhs) const { /*...*/ }     bool operator != (const employeeinfo &rhs) const { return !(*this == rhs); }     bool operator < (const employeeinfo & ) const;     uint32_t read(::apache::thrift::protocol::tprotocol* iprot);     uint32_t write(::apache::thrift::protocol::tprotocol* oprot) const; }; 

employee_types.cpp

uint32_t employeeinfo::read(::apache::thrift::protocol::tprotocol* iprot) {     uint32_t xfer = 0;     std::string fname;     ::apache::thrift::protocol::ttype ftype;     int16_t fid;     xfer += iprot->readstructbegin(fname);     using ::apache::thrift::protocol::tprotocolexception;     while (true)     {         xfer += iprot->readfieldbegin(fname, ftype, fid);         if (ftype == ::apache::thrift::protocol::t_stop) {             break;         }         switch (fid)         {             // removed case statements deal reading other fields         case 6:             if (ftype == ::apache::thrift::protocol::t_set) {                 {                     this->savings.clear();                     uint32_t _size6;                     ::apache::thrift::protocol::ttype _etype9;                     iprot->readsetbegin(_etype9, _size6);                     uint32_t _i10;                     (_i10 = 0; _i10 < _size6; ++_i10)                     {                         savingsinfo _elem11;                         xfer += _elem11.read(iprot);                         this->savings.insert(_elem11);                     }                     iprot->readsetend();                 }                 this->__isset.savings = true;             } else {                 xfer += iprot->skip(ftype);             }             break;         default:             xfer += iprot->skip(ftype);             break;         }         xfer += iprot->readfieldend();     }     xfer += iprot->readstructend();     return xfer; }  uint32_t employeeinfo::write(::apache::thrift::protocol::tprotocol* oprot) const {     uint32_t xfer = 0;     // removed write statements other fields     xfer += oprot->writestructbegin("employeeinfo");     xfer += oprot->writefieldbegin("savings", ::apache::thrift::protocol::t_set, 6);     {         xfer += oprot->writesetbegin(::apache::thrift::protocol::t_struct,                this->savings.size());         std::set<savingsinfo> ::const_iterator _iter13;         (_iter13 = this->savings.begin(); _iter13 != this->savings.end(); ++_iter13)         {             xfer += (*_iter13).write(oprot);         }         xfer += oprot->writesetend();     }     xfer += oprot->writefieldend();     xfer += oprot->writefieldstop();     xfer += oprot->writestructend();     return xfer; } 

couple of other things have tried:

  1. instead of set<savingsinfo>, if use savingsinfo, works fine.
  2. commented "operator <" in employee_types.h since couldn't figure out getting used. got following build error

building file: ../src/employee_types.cpp invoking: gcc c++ compiler g++ -i/usr/local/include/thrift -i/users/raghava/software/boost_c++_library/boost_1_43_0 -o0 -g3 -wall -c -fmessage-length=0 -mmd -mp -mf"src/employee_types.d" -mt"src/employee_types.d" -o"src/employee_types.o" "../src/employee_types.cpp" /usr/include/c++/4.2.1/bits/stl_function.h: in member function 'bool std::less<_tp>::operator()(const _tp&, const _tp&) const [with _tp = com::xxxx::thrift::employee::savingsinfo]': /usr/include/c++/4.2.1/bits/stl_tree.h:982: instantiated 'std::pair::iterator, bool> std::_rb_tree<_key, _val, _keyofvalue, _compare, _alloc>::_m_insert_unique(const _val&) [with _key = com::xxxx::thrift::employee::savingsinfo, _val = com::xxxx::thrift::employee::savingsinfo, _keyofvalue = std::_identity, _compare = std::less, _alloc = std::allocator]' /usr/include/c++/4.2.1/bits/stl_set.h:307: instantiated 'std::pair, _compare, typename _alloc::rebind<_key>::other>::const_iterator, bool> std::set<_key, _compare, _alloc>::insert(const _key&) [with _key = com::xxxx::thrift::employee::savingsinfo, _compare = std::less, _alloc = std::allocator]' ../src/employee_types.cpp:163: instantiated here /usr/include/c++/4.2.1/bits/stl_function.h:227: error: no match 'operator<' in '__x < __y' make: *** [src/employee_types.o] error 1

complete source code of these 2 files given in below links. other link in comments (i cannot post until 10 pts of reputation).

employee_types.cpp -- http://pastebin.com/7dltstck
employee_types.h -- http://pastebin.com/jgze8v6j

thank you.

regards, raghava.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -