Ошибка компоновщика C ++ после изменения в файле thrift - PullRequest
1 голос
/ 25 июля 2010

Я думаю, что это связано с ошибкой компоновщика C ++, а не с экономией. Я внес изменения в файл Thrift и восстановил классы cpp & java. После этого изменения я начал получать ошибки компоновщика в cpp. Вот ошибка

Неопределенные символы:

"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 <br/> ld: symbol(s) not found <br/> collect2: ld returned 1 exit status <br/> make: *** [ThriftCPPSamples] Error 1

Я добавил тип SavingsInfo в комиссионный файл, это изменение, которое я сделал. Я даю все опции, упомянутые в документе, g ++. Я дал -I/usr/local/include/thrift, -I/path-to-boost, -L/path-to-boost-lib, -lthrift. Но после изменения я начал получать вышеуказанную ошибку компоновщика. Я не мог понять причину этого. Ошибка указывает на то, что было сгенерировано экономией. В чем может быть причина ошибки?

Эта ошибка относится к «оператору <», поэтому я публикую только соответствующий ему код. Полный код доступен по двум ссылкам, указанным в конце. </p>

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 the case statements which deal with 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;
                    for (_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 the write statements for 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;
        for (_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;
}

Пара других вещей, которые я пробовал:

  1. Вместо набора , если я использую SavingsInfo, он работает нормально.
  2. Комментарий "operator <" в employee_types.h, поскольку я не мог понять, к чему это привыкло. Я получил следующую ошибку сборки </li>

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 from '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 from '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 from here /usr/include/c++/4.2.1/bits/stl_function.h:227: error: no match for 'operator<' in '__x < __y' make: *** [src/employee_types.o] Error 1

Полный исходный код этих 2 файлов приведен в ссылках ниже. Другая ссылка есть в комментариях (я не могу опубликовать ее, пока не получу 10 баллов репутации).

employee_types.cpp - http://pastebin.com/7dLtstCK
employee_types.h - http://pastebin.com/JGzE8V6J

Спасибо.

С уважением, Raghava.

...