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

// 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<<buff<<endl;


    People myprotobuf_rd;
    myprotobuf_rd.ParseFromArray(buff,BUFFSIZE);
    cout<<"name :"<<myprotobuf_rd.name()<<"\n"
        <<"id :"<<myprotobuf_rd.id()<<"\n"
        <<"email :"<<myprotobuf_rd.email()<<endl;


    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值