用Cmake生成protoc.exe(protobuf编译器)

protobuf编译器可以把,proto文件编译成对应语音类型的脚本文件。
编译器可以直接在Protobuf的GitHub上下载 上篇文章有介绍 http://www.jianshu.com/p/b135676dbe8d

除了下载外,我们也可以从GitHub上下载Protobuf源文件自己编译,源文件里提供了多种编译方式的配置文件。
这次主要介绍的是用 Cmake 编译 (Cmake下载地址: https://cmake.org/download/)

Camke界面是这样的:

用Cmake生成protoc.exe(protobuf编译器)_第1张图片
Paste_Image.png

Where is the source code : 很明显,让你选择源文件路径
Where to build the binaries: 让你选择输出路径

源文件路径你需要选择protobuf源文件下的Cmake文件夹,输出路径就随便了。

用Cmake生成protoc.exe(protobuf编译器)_第2张图片
Paste_Image.png

设置完成后点击 Configure ,点完后会让你选择使用哪个生成工具

用Cmake生成protoc.exe(protobuf编译器)_第3张图片
Paste_Image.png

在下选择的是VS2017,有一点需要注意,因为编译需要用到C++的模块功能,所以需要具备C++环境,使用VS2017的同学只需要去Instanll界面设置添加一下就可以了

用Cmake生成protoc.exe(protobuf编译器)_第4张图片
Paste_Image.png

OK 开始编译,
编译的时候如果出现这种情况

用Cmake生成protoc.exe(protobuf编译器)_第5张图片
Paste_Image.png

是因为我们没有测试环境,直接把protobuf_BUILD_TESTS 取消就可以了,再点击Configure 继续编译

用Cmake生成protoc.exe(protobuf编译器)_第6张图片
Paste_Image.png

OK 编译完成是这样

用Cmake生成protoc.exe(protobuf编译器)_第7张图片
Paste_Image.png

去输出路径/Debug文件夹下可以找到编译出来的protoc.exe。

你可能感兴趣的:(用Cmake生成protoc.exe(protobuf编译器))