c++ - protobuf 与 zeromq 与 C++ 的链接错误

标签 c++ cmake protocol-buffers zeromq

我正在尝试在 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.confsudo ldconfig 中包含了 /usr/local/lib

我怀疑这与 repeat 字段或 protobuf 的命名空间有关。

谢谢。

最佳答案

我找到了链接错误的原因。我安装了不同版本的 libprotobuf 库。我做了 ls | grep 'libproto' in /usr/lib//usr/local/lib 结果你可以在图片中看到。我手动删除了/usr/lib中与libprotobuf相关的文件,能够编译代码。

enter image description here

关于c++ - protobuf 与 zeromq 与 C++ 的链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24427461/

相关文章:

android - QtCreator 甚至无法构建空项目 - 执行此行时发生以下错误

visual-studio - 如何在 CMake 中打印 WORKING_DIRECTORY?

c++ - 包含 libpqxx 会导致使用 CMake 在 WSL 上构建失败

c++ - 检查工作 CXX 编译器 :/cygdrive/c/cygwin64/bin/clang++ -- broken

go - 从 --go_out=plugins 切换到 -go-grpc_out PATH 问题

c++ - 如果派生类只包含自动变量成员,是否需要有虚析构函数?

c++ - 概括 Fortran 中特定声明类型的操作

c - 如何附加到 C 宏中的参数名称

C++ 程序不响应任务栏中的平铺/级联窗口

java - 高效地将 Java 列表转换为 Matlab 矩阵