2012-01-16 3 views
2

Я использую C++ в ubuntu с apatana в качестве моей IDE.Устранение ошибок при использовании прото-учебника

Я скомпилировал файл addressbook.proto следующим образом:

protoc -I=/home/workspace/rtb/src/ --cpp_out=/home/workspace/rtb/src/ /home/workspace/rtb/src/addressbook.proto 

Затем я включил файл вывода заголовка в мой код на С ++ следующим образом:

#include "addressbook.pb.h" 

Это должно быть. Правильно?

Когда я создаю ... Я получаю список ошибок, которые слишком длинны. ниже приведены последние несколько строк. Что мне не хватает? Как использовать прото-буферы в C++?

./src/addressbook.pb.o:(.rodata._ZTVN8tutorial11AddressBookE[vtable for tutorial::AddressBook]+0x40): undefined reference to `google::protobuf::Message::InitializationErrorString() const' 
./src/addressbook.pb.o:(.rodata._ZTVN8tutorial11AddressBookE[vtable for tutorial::AddressBook]+0x48): undefined reference to `google::protobuf::Message::CheckTypeAndMergeFrom(google::protobuf::MessageLite const&)' 
./src/addressbook.pb.o:(.rodata._ZTVN8tutorial11AddressBookE[vtable for tutorial::AddressBook]+0x88): undefined reference to `google::protobuf::Message::DiscardUnknownFields()' 
./src/addressbook.pb.o:(.rodata._ZTVN8tutorial11AddressBookE[vtable for tutorial::AddressBook]+0x90): undefined reference to `google::protobuf::Message::SpaceUsed() const' 
./src/addressbook.pb.o:(.rodata._ZTVN8tutorial6PersonE[vtable for tutorial::Person]+0x20): undefined reference to `google::protobuf::Message::GetTypeName() const' 
./src/addressbook.pb.o:(.rodata._ZTVN8tutorial6PersonE[vtable for tutorial::Person]+0x40): undefined reference to `google::protobuf::Message::InitializationErrorString() const' 
./src/addressbook.pb.o:(.rodata._ZTVN8tutorial6PersonE[vtable for tutorial::Person]+0x48): undefined reference to `google::protobuf::Message::CheckTypeAndMergeFrom(google::protobuf::MessageLite const&)' 
./src/addressbook.pb.o:(.rodata._ZTVN8tutorial6PersonE[vtable for tutorial::Person]+0x88): undefined reference to `google::protobuf::Message::DiscardUnknownFields()' 
./src/addressbook.pb.o:(.rodata._ZTVN8tutorial6PersonE[vtable for tutorial::Person]+0x90): undefined reference to `google::protobuf::Message::SpaceUsed() const' 
./src/addressbook.pb.o:(.rodata._ZTVN8tutorial18Person_PhoneNumberE[vtable for tutorial::Person_PhoneNumber]+0x20): undefined reference to `google::protobuf::Message::GetTypeName() const' 
./src/addressbook.pb.o:(.rodata._ZTVN8tutorial18Person_PhoneNumberE[vtable for tutorial::Person_PhoneNumber]+0x40): undefined reference to `google::protobuf::Message::InitializationErrorString() const' 
./src/addressbook.pb.o:(.rodata._ZTVN8tutorial18Person_PhoneNumberE[vtable for tutorial::Person_PhoneNumber]+0x48): undefined reference to `google::protobuf::Message::CheckTypeAndMergeFrom(google::protobuf::MessageLite const&)' 
./src/addressbook.pb.o:(.rodata._ZTVN8tutorial18Person_PhoneNumberE[vtable for tutorial::Person_PhoneNumber]+0x88): undefined reference to `google::protobuf::Message::DiscardUnknownFields()' 
./src/addressbook.pb.o:(.rodata._ZTVN8tutorial18Person_PhoneNumberE[vtable for tutorial::Person_PhoneNumber]+0x90): undefined reference to `google::protobuf::Message::SpaceUsed() const' 
./src/addressbook.pb.o:(.rodata._ZTIN8tutorial11AddressBookE[typeinfo for tutorial::AddressBook]+0x10): undefined reference to `typeinfo for google::protobuf::Message' 
./src/addressbook.pb.o:(.rodata._ZTIN8tutorial6PersonE[typeinfo for tutorial::Person]+0x10): undefined reference to `typeinfo for google::protobuf::Message' 
./src/addressbook.pb.o:(.rodata._ZTIN8tutorial18Person_PhoneNumberE[typeinfo for tutorial::Person_PhoneNumber]+0x10): undefined reference to `typeinfo for google::protobuf::Message' 
collect2: ld returned 1 exit status 
make: *** [rtb] Error 1 
+0

Это связывание ошибок. Убедитесь, что вы связываетесь с библиотекой. –

+0

решил: мне нужно было добавить -lprotobuf –

ответ

6

Вы должны связать свой код с библиотекой буферов протоколов. Скорее всего, вам нужен флаг:
-l protobuf.

+0

вы можете ввести всю команду для запуска cpp-файла –

+0

Фактически я запускаю файл tryProto.cpp как: g ++ -l protobuf tryProto.cpp и все еще получаю ту же ошибку, добавив -lprotobuf не имеет имеет какое-либо значение, есть ли что-нибудь, чего я не вижу –

Смежные вопросы