https://github.com/protocolbuffers/protobuf/blob/main/cmake/README.md
Getting Sources
You can get the latest stable source packages from the release page:
您可以从发布页面获得最新的稳定源代码包:
https://github.com/protocolbuffers/protobuf/releases/latest
For example: if you only need C++, download protobuf-cpp-[VERSION].tar.gz; if you need C++ and Java, download protobuf-java-[VERSION].tar.gz (every package contains C++ source already); if you need C++ and multiple other languages, download protobuf-all-[VERSION].tar.gz.
例如: 如果您只需要 C + + ,请下载 Protobuf-cpp-[ VERION ]。如果您需要 C + + 和 Java,请下载 Protobuf-Java-[ VERION ]。Gz (每个包都已经包含 C + + 源代码) ; 如果您需要 C + + 和其他多种语言,请下载 Protobuf-all-[ VERION ]。Tar.gz.
代码目录
C:\Path\to_2010\src\protobuf
需要确保已经安装了cmake
cmd 中依次打入以下命令,生成vs2010 项目文件
Microsoft Windows [版本 10.0.19042.1288]
(c) Microsoft Corporation。保留所有权利。
C:\Path\to_2010>mkdir build
C:\Path\to_2010>cd build
C:\Path\to_2010\build>mkdir protobuf
C:\Path\to_2010\build>cd protobuf
C:\Path\to_2010\build\protobuf>mkdir solution & cd solution
C:\Path\to_2010\build\protobuf\solution>cmake -G "Visual Studio 10 2010 Win64" ^
More? -DCMAKE_INSTALL_PREFIX=C:\Path\to_2010\install ^
More? C:\Path\to_2010\src\protobuf
最后会在此目录下面生成vs2010项目文件
C:\Path\to_2010\build\protobuf\solution
如果需要生成其他版本的vs项目文件,
只需要cmake -G "Visual Studio 10 2010 Win64" ^这句话变一下就可以
可以用cmake -G 命令查看支持的版本
C:\Path\to_2010\build\protobuf\solution>cmake -G
方法二
1. 下载 Protocol Buffers v2.6.1
https://github.com/google/protobuf/releases/tag/v2.6.1
版本参考https://blog.csdn.net/xiaofan_0208/article/details/71478852
导入库文件
libprotobuf.lib
libprotobuf-lite.lib
libprotoc.lib
- // mytest.cpp : 定义控制台应用程序的入口点。
- //
-
- #include "stdafx.h"
- #include "people.pb.h"
-
- #include "iostream"
- using namespace std;
-
- using namespace PeopleT::Test;
-
-
- const int BUFFSIZE = 128;
-
- int _tmain(int argc, _TCHAR* argv[])
- {
- People myprotobuf;
- char buff[BUFFSIZE];
-
-
- myprotobuf.set_name("wang");
- myprotobuf.set_id(2);
- myprotobuf.set_email("abc@123.com");
-
- //protobuf的序列化方式之一
- memset(buff,0,BUFFSIZE);
- myprotobuf.SerializeToArray(buff,BUFFSIZE);
-
- cout<
-
-
- People myprotobuf_rd;
- myprotobuf_rd.ParseFromArray(buff,BUFFSIZE);
- cout<<"name :"<
name()<<"\n" - <<"id :"<
id()<<"\n" - <<"email :"<
email()< -
-
- return 0;
- }
-
相关阅读:
什么是设计模式?
软考-高级-信息系统项目管理师教程 第四版【第23章-组织通用管理-思维导图】
ClickHouse技术研究及语法简介
基于android的心理自测咨询APP(ssm+uinapp+Mysql)
java计算机毕业设计springboot+vue学生宿舍管理系统 elementui
适用于企业级的勒索软件风险防范规范
【C++进阶】二叉树进阶之二叉搜索树
MySQL read 查询语句5 增强
尚优选项目流程&布局参数
【排序算法】Leetcode刷题心得
-
原文地址:https://blog.csdn.net/henry3695/article/details/127708020