在Eclipse(C ++)上运行protobuf给出的示例

时间:2019-01-21 11:29:25

标签: c++ eclipse eclipse-plugin protocol-buffers

我正在尝试使用和理解协议缓冲区。我已经安装了该库并尝试运行该示例。但是我看不到我要去哪里。

下面我将描述所有步骤: 1。。按照说明安装protobuf编译器https://github.com/protocolbuffers/protobuf/tree/master/src

2。。按照说明将Protobuf插件安装到Eclipse https://github.com/google/protobuf-dt上 (不确定是否需要)。

3。。打开 protobuf / examples / 目录。在Eclipse中运行 add_person.cc 编译器产生以下错误。我看到这是一个链接错误。但是我不确定我要去哪里。

make all 
Building file: ../src/add_person.cc
Invoking: GCC C++ Compiler
g++ -std=c++11 -I/home/rohan/Downloads/Utilities/protobuf/examples -O0 -g3 -Wall -c -fmessage-length=0 -pthread -MMD -MP -MF"src/add_person.d" -o "src/add_person.o" "../src/add_person.cc"
Finished building: ../src/add_person.cc

Building target: add_person
Invoking: GCC C++ Linker
g++ -L/usr/lib64 -pthread -o "add_person"  ./src/add_person.o   -lprotobuf
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: ./src/add_person.o: in function `main':
/home/rohan/eclipse-workspace/add_person/Debug/../src/add_person.cc:81: undefined reference to `tutorial::AddressBook::AddressBook()'
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: /home/rohan/eclipse-workspace/add_person/Debug/../src/add_person.cc:81: undefined reference to `tutorial::AddressBook::~AddressBook()'
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: /home/rohan/eclipse-workspace/add_person/Debug/../src/add_person.cc:81: undefined reference to `tutorial::AddressBook::~AddressBook()'
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: ./src/add_person.o: in function `google::protobuf::internal::GenericTypeHandler<tutorial::Person_PhoneNumber>::New(google::protobuf::Arena*)':
/usr/local/include/google/protobuf/repeated_field.h:656: undefined reference to `tutorial::Person_PhoneNumber* google::protobuf::Arena::CreateMaybeMessage<tutorial::Person_PhoneNumber>(google::protobuf::Arena*)'
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: ./src/add_person.o: in function `google::protobuf::internal::GenericTypeHandler<tutorial::Person>::New(google::protobuf::Arena*)':
/usr/local/include/google/protobuf/repeated_field.h:656: undefined reference to `tutorial::Person* google::protobuf::Arena::CreateMaybeMessage<tutorial::Person>(google::protobuf::Arena*)'
collect2: error: ld returned 1 exit status
make: *** [makefile:47: add_person] Error 1
"make all" terminated with exit code 2. Build might be incomplete.

1 个答案:

答案 0 :(得分:0)

请注意:这可能无法解决其他人的问题。

我在eclipse中运行的示例程序在项目中仅具有add_person.cc文件。并且包含协议缓冲区类和定义(addressbook.pb.haddressbook.pb.cc)的文件不在项目中。相反,我将它们添加为-I\path\to\the\directory\,从而产生了该错误。

对于这个最小的问题,我只需要移动/复制项目中的addressbook.pb.haddressbook.pb.cc文件。