使用proto教程时链接错误

时间:2012-01-16 04:46:42

标签: c++ protocol-buffers

我在ubuntu中使用c ++和apatana作为我的IDE。

我编写了addressbook.proto文件,如下所示:

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

然后我将输出头文件包含在我的c ++代码中,如下所示:

#include "addressbook.pb.h"

那应该是它。正确?

当我构建时......我得到一个错误列表,列表太长了。下面是最后几行。我错过了什么?如何在c ++中使用proto缓冲区?

./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

1 个答案:

答案 0 :(得分:6)

您必须将代码链接到协议缓冲区库。最有可能的是,您需要的旗帜是-l protobuf