C++ 使用proto教程时链接错误

C++ 使用proto教程时链接错误,c++,protocol-buffers,C++,Protocol Buffers,我在Ubuntu中使用C++,以ApTaNa作为IDE。< /P> 我编译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++代码中: protoc -I=/home/workspace/rt

我在Ubuntu中使用C++,以ApTaNa作为IDE。< /P> 我编译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++代码中:

protoc -I=/home/workspace/rtb/src/ --cpp_out=/home/workspace/rtb/src/ /home/workspace/rtb/src/addressbook.proto
#include "addressbook.pb.h"
应该是这样。对吧?

当我构建时,我会得到一个错误列表,这个列表太长了。下面是最后几行。我错过了什么?在C++中如何使用PROTO缓冲区?< /P>
./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

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

这些是链接错误。请确保您正在链接到库。已解决:我必须添加-lprotobuf事实上,我正在运行tryProto.cpp文件作为:g++-l protobuf tryProto.cpp,但仍然得到相同的错误,添加-lprotobuf没有任何区别,我有什么遗漏吗