使用protobuf的简单流程记录、编译protobuf时遇到的坑 以及 链接protobuf的坑

简介: 使用protobuf的简单流程记录、编译protobuf时遇到的坑 以及 链接protobuf的坑

protobuf 简单流程:

1、写.proto文件,语法 可以看

https://blog.csdn.net/lcuwb/article/details/90705397

2、使用指令编译proto文件,如果是生成c++ 的资源,则会生成 cc文件, 和 .h文件

protoc -I[proto文件的路径]  --cpp_out=./[cc, .h文件生成的路径]  *.proto(proto文件的位置)

protoc -I./ -cpp_out=./ ./project.proto

3、写一个cpp文件,应用protobuf

      include  proto 生成的.h文件

      对数据进行序列化,和反序列化,进行调试

4、编译的时候 需要加上 -std=c++1 , -lthread , -lprotobuf           ---最坑的位置在这里

例如:

g++ test_proto.cpp project.pb.cc -o test_proto -lprotobuf -std=c++11 -lpthread

如果没有加上-lthread  会报以下错误

[libprotobuf FATAL google/protobuf/generated_message_util.cc:783] CHECK failed: (scc->visit_status.load(std::memory_order_relaxed)) == (SCCInfoBase::kRunning):

 

如果没有加上-std=c++11 会报以下错误

/usr/local/include/google/protobuf/metadata_lite.h:160:52: error: no matching function for call to ‘google::protobuf::Arena::Create(google::protobuf::Arena*&)’
    Container* container = Arena::Create<Container>(my_arena);

 

如果没有加上-lprotobuf 会报以下错误

project.pb.cc:(.text+0x5fc): undefined reference to `google::protobuf::io::CodedInputStream::ReadTagFallback(unsigned int)'
project.pb.cc:(.text+0x723): undefined reference to `google::protobuf::internal::WireFormatLite::VerifyUtf8String(char const*, int, google::protobuf::internal::WireFormatLite::Operation, char const*)'
project.pb.cc:(.text+0x7b5): undefined reference to `google::protobuf::internal::WireFormatLite::VerifyUtf8String(char const*, int, google::protobuf::internal::WireFormatLite::Operation, char const*)'
project.pb.cc:(.text+0x849): undefined reference to `google::protobuf::internal::WireFormat::SkipField(google::protobuf::io::CodedInputStream*, unsigned int, google::protobuf::UnknownFieldSet*)'
/tmp/cc1U6w5J.o: In function `Account::SerializeWithCachedSizes(google::protobuf::io::CodedOutputStream*) const':
project.pb.cc:(.text+0x8eb): undefined reference to `google::protobuf::internal::WireFormatLite::WriteUInt64(int, unsigned long, google::protobuf::io::CodedOutputStream*)

 

5、运行可执行程序

 

 

 

相关文章
protobuf实战-----之Mac 安装篇
因为项目的需要,所以,要在mac上安装配置protobuf。其中走了不少弯路。
2131 0
|
网络协议 Ubuntu
如何修改wsl的Ubuntu的dns,固定dns
本文介绍了如何在 WSL 中配置网络设置。首先,修改 `/etc/wsl.conf` 文件,添加 `generateResolvConf = false`。其次,编辑 `/etc/resolv.conf` 文件,指定 DNS 服务器地址。最后,重启 WSL 即可生效。
2469 2
|
NoSQL 安全 Linux
Linux 中 core dump 文件的作用和使用方法
Linux 中 core dump 文件的作用和使用方法
2900 1
|
Java API Android开发
DDS、FastDDS、OpenDDS扫盲
DDS、FastDDS、OpenDDS扫盲
3860 0
|
Cloud Native IDE Go
Protobuf在IDEA中的插件安装教程
Protobuf在IDEA中的插件安装教程
1433 0
|
Shell Linux Docker
Docker -v 挂载主机目录到容器中(及数据卷容器)
Docker -v 挂载主机目录到容器中(及数据卷容器)
2844 0
|
安全 网络协议 Ubuntu
【常见开源库的二次开发】HTTP之libcurl库——libcurl使用(二)
【常见开源库的二次开发】HTTP之libcurl库——libcurl使用(二)
4126 2
|
NoSQL Linux
Linux系统调试中出现核心转储(core dump)的问题
Linux系统调试中出现核心转储(core dump)的问题
3552 0
|
存储 安全 数据安全/隐私保护
穿越编程之海:探索谷歌Protocol Buffers库在C++中的应用
穿越编程之海:探索谷歌Protocol Buffers库在C++中的应用
1091 0
|
Web App开发 前端开发 JavaScript
Web前端项目的跨平台桌面客户端打包方案之——CEF框架
Chromium Embedded Framework (CEF) 是一个基于 Google Chromium 项目的开源 Web 浏览器控件,旨在为第三方应用提供嵌入式浏览器支持。CEF 隔离了底层 Chromium 和 Blink 的复杂性,提供了稳定的产品级 API。它支持 Windows、Linux 和 Mac 平台,不仅限于 C/C++ 接口,还支持多种语言。CEF 功能强大,性能优异,广泛应用于桌面端开发,如 QQ、微信、网易云音乐等。CEF 开源且采用 BSD 授权,商业友好,装机量已超 1 亿。此外,GitHub 项目 CefDetector 可帮助检测电脑中使用 CEF
3810 3