我正在尝试在 C++ 中将 protobuf 与 zeromq 结合使用。我收到以下链接错误
/tmp/cco9X8QH.o: In function `google::protobuf::GoogleOnceInit(long*, void (*)())':
laserscan.pb.cc:(.text._ZN6google8protobuf14GoogleOnceInitEPlPFvvE[google::protobuf::GoogleOnceInit(long*, void (*)())]+0x4f): undefined reference to `google::protobuf::GoogleOnceInitImpl(long*, google::protobuf::Closure*)'
/tmp/cco9X8QH.o: In function `bool google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<float, (google::protobuf::internal::WireFormatLite::FieldType)2>(google::protobuf::io::CodedInputStream*, google::protobuf::RepeatedField<float>*)':
laserscan.pb.cc:(.text._ZN6google8protobuf8internal14WireFormatLite19ReadPackedPrimitiveIfLNS2_9FieldTypeE2EEEbPNS0_2io16CodedInputStreamEPNS0_13RepeatedFieldIT_EE[bool google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<float, (google::protobuf::internal::WireFormatLite::FieldType)2>(google::protobuf::io::CodedInputStream*, google::protobuf::RepeatedField<float>*)]+0x85): undefined reference to `google::protobuf::io::CodedInputStream::BytesUntilLimit() const'
collect2: ld returned 1 exit status
这是我的信息
扫描原型(prototype)
message Scan{
required float scan_time=1; // time between scans [seconds]
repeated float ranges=2;
}
这是我填写消息并发送的代码。
发件人.cpp
Scan proto_msg;
proto_msg.set_scan_time(0.5);
proto_msg.add_ranges(1.0);
std::string msg_str;
proto_msg.SerializeToString(&msg_str);
zmq::message_t request (msg_str.size());
memcpy ((void *) request.data(), msg_str.c_str(),msg_str.size());
socket.send (request);
构建命令:
g++ sender.cpp scan.pb.cc scan.pb.h -I /home/sender -l protobuf -l zmq
我在 /etc/ld.so.conf
和 sudo ldconfig
中包含了 /usr/local/lib
。
我怀疑这与 repeat 字段或 protobuf 的命名空间有关。
谢谢。
最佳答案
我找到了链接错误的原因。我安装了不同版本的 libprotobuf
库。我做了 ls | grep 'libproto'
in /usr/lib/
和 /usr/local/lib
结果你可以在图片中看到。我手动删除了/usr/lib
中与libprotobuf
相关的文件,能够编译代码。
关于c++ - protobuf 与 zeromq 与 C++ 的链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24427461/