• protobuf用cmake生成vs2010项目文件


    ​​​​​​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

    Download | 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

    1. // mytest.cpp : 定义控制台应用程序的入口点。
    2. //
    3. #include "stdafx.h"
    4. #include "people.pb.h"
    5. #include "iostream"
    6. using namespace std;
    7. using namespace PeopleT::Test;
    8. const int BUFFSIZE = 128;
    9. int _tmain(int argc, _TCHAR* argv[])
    10. {
    11.     People myprotobuf;
    12.     char buff[BUFFSIZE];
    13.     myprotobuf.set_name("wang");
    14.     myprotobuf.set_id(2);
    15.     myprotobuf.set_email("abc@123.com");
    16.     //protobuf的序列化方式之一
    17.     memset(buff,0,BUFFSIZE);
    18.     myprotobuf.SerializeToArray(buff,BUFFSIZE);
    19.     cout<
    20.     People myprotobuf_rd;
    21.     myprotobuf_rd.ParseFromArray(buff,BUFFSIZE);
    22.     cout<<"name :"<name()<<"\n"
    23.         <<"id :"<id()<<"\n"
    24.         <<"email :"<email()<
    25.     return 0;
    26. }

  • 相关阅读:
    什么是设计模式?
    ​软考-高级-信息系统项目管理师教程 第四版【第23章-组织通用管理-思维导图】​
    ClickHouse技术研究及语法简介
    基于android的心理自测咨询APP(ssm+uinapp+Mysql)
    java计算机毕业设计springboot+vue学生宿舍管理系统 elementui
    适用于企业级的勒索软件风险防范规范
    【C++进阶】二叉树进阶之二叉搜索树
    MySQL read 查询语句5 增强
    尚优选项目流程&布局参数
    【排序算法】Leetcode刷题心得
  • 原文地址:https://blog.csdn.net/henry3695/article/details/127708020