在C 中使用Protobuf 3.2的困难
Difficulty using Protobuf 3.2 in C++
本文关键字:Protobuf 更新时间:2023-10-16
我正在尝试在C 中使用Protobuf,但是很难让它做任何有意义的事情。我正在使用Visual Studio 2015。
我构建了Protobuf库。我正在使用GitHub的最新版本。
我创建了一个.proto文件:
syntax = "proto3";
package Networking;
message Robot{
message KinematicLinkProto {
string name = 1;
float x_pos = 2;
float y_pos = 3;
float z_pos = 4;
float roll = 5;
float pitch = 6;
float yaw = 7;
float x_scale = 8;
float y_scale = 9;
float z_scale = 10;
}
repeated KinematicLinkProto links = 1;
}
我对此进行了编译,然后尝试将其添加到一个项目中:
#include "Robot.pb.h"
int main(int argc, char **argv)
{
Networking::Robot robot_message;
return 0;
}
我的链接器链接libprotobuf.lib。我正在将其构建为/MD和Libprotobuf作为/MD。
由于某种原因,这个简单的程序具有以下两个链接器错误:
Error LNK2019 unresolved external symbol "private: static bool google::protobuf::io::CodedOutputStream::default_serialization_deterministic_" (?default_serialization_deterministic_@CodedOutputStream@io@protobuf@google@@0_NA) referenced in function "public: virtual unsigned char * __cdecl Networking::Robot::SerializeWithCachedSizesToArray(unsigned char *)const " (?SerializeWithCachedSizesToArray@Robot@Networking@@UEBAPEAEPEAE@Z)
Error LNK2019 unresolved external symbol "class google::protobuf::internal::ExplicitlyConstructed<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > google::protobuf::internal::fixed_address_empty_string" (?fixed_address_empty_string@internal@protobuf@google@@3V?$ExplicitlyConstructed@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@123@A) referenced in function "protected: void __cdecl google::protobuf::internal::RepeatedPtrFieldBase::Clear<class google::protobuf::RepeatedPtrField<class Networking::Robot_KinematicLinkProto>::TypeHandler>(void)" (??$Clear@VTypeHandler@?$RepeatedPtrField@VRobot_KinematicLinkProto@Networking@@@protobuf@google@@@RepeatedPtrFieldBase@internal@protobuf@google@@IEAAXXZ)
我很困惑 - 这是一个非常简单的程序。我可能做错了什么?
编辑:一位同事编译了Proto 3001000。此版本似乎很有用。我很好奇3002000破坏一切。
如果使用dll,请使用
#define PROTOBUF_USE_DLLS
相关文章:
- 带有Protobuf序列化的C++Hazelcast:字符串不是UTF-8格式的
- Google protobuf 时间戳未声明标识符,在 Windows 上具有C++
- 如何继承 Protobuf 生成的C++类
- FlatBuffers/Protobuf 中是否有支持任意 24 位有符号整数定义的可移植二进制序列化架构?
- gRPC 找不到 Protobuf 库
- protobuf C++ SQLite handle blob data
- Protobuf ShortDebugString() crash
- Protobuf中重复字段的问题.使用重复字段进行序列化/反序列化的更好方法是什么?
- CMake 在编译 Google 的 protobuf 示例时找不到 protobuf
- C++ protobuf SerializedData
- 从 Any 包中提取和匹配 protobuf 消息类型名的首选方法
- protobuf 的 ParseFromString 函数返回 false
- C++:如何通过 curl 调用使用 HTTP post 请求发送二进制数据(protobuf 数据)
- 防止 GNU Make 在每次构建时生成 protobuf 代码
- 如何在C++中分配嵌套的protobuf而不进行复制
- E/libc++abi:终止于类型为google::protobuf::FatalException的未捕获异常
- 修改原始protobuf流
- protobuf,如何在protobuf消息中遍历所有集合字段,我不知道详细信息?(C++)
- Protobuf中的ParseFromArray和ParseFromString之间有什么区别
- 如何检查字节数组是protobuf序列化字节数组还是普通字节数组