使用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、运行可执行程序

 

 

 

相关文章
|
Go API 开发工具
Opentelemetry SDK的简单用法
Opentelemetry SDK的简单用法
476 3
|
安全 测试技术 C++
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)
最近用到了gRPC,配置了很长时间,分享一下配置过程。先来看一下我准备的文件包(资源我放在最后)
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)
|
存储 安全 数据安全/隐私保护
穿越编程之海:探索谷歌Protocol Buffers库在C++中的应用
穿越编程之海:探索谷歌Protocol Buffers库在C++中的应用
1406 0
|
Cloud Native 开发工具 存储
OpenTelemetry-可观察性的新时代
Ops领域两个网红项目OpenTracing和OpenCensus终于走到了一起,可观察性统一的标准化已经扬帆起航。这篇文章旨在抛砖引玉,希望能够和更多的同学一起交流可观察性相关的内容。
9202 0
|
UED
使用约束布局实现居中对齐效果
【10月更文挑战第24天】我们可以看到使用约束布局实现居中对齐并不是一件难事。只要掌握了基本的方法和技巧,结合具体的场景进行灵活运用,就能轻松地实现各种居中对齐效果。在实际开发中,要不断实践和总结经验,以便更好地发挥约束布局的优势,为用户带来更优质的界面体验。
759 1
|
Linux TensorFlow 算法框架/工具
在Linux上安装其他版本的cmake 或 升级cmake
在Linux上安装其他版本的cmake 或 升级cmake
3959 2
|
C语言 C++ Windows
windows下编译protobuf
windows下编译protobuf
968 0
|
存储 缓存 IDE
CMake之编写属于自己的Findxxx.cmake文件:定义一个定制化的CMakeLists.txt文件
CMake之编写属于自己的Findxxx.cmake文件:定义一个定制化的CMakeLists.txt文件
677 1

热门文章

最新文章