这里主要是使用cmake生成vs2015 工程。然后编译自己需要的库文件和proto.exe

工具:

CMAKE:http://www.cmake.org

源码地址:https://github.com/protocolbuffers/protobuf/releases

VS2015 已经安装完成

版本选择:(根据自己需要选择相应的版本)

cmake:cmake version 3.17.20200511-g8787079

protobuf源码下载的是3.9.2 (我下载的是souce code zip)

编译:

主要参照protobuf源码下cmake的readme.md

1.打开Command Prompt   选择x86  和 x64 都行

编译vs2015 protobuf

以下操作是在dos里面进行的

2.跳转到源码所在的路径(用cd 路径),创建install文件

mkdir install

3.设置cmake 到环境变量  (可以用set 看一下 path中是否已经有了cmake的路径,如果有这一步省略)

set PATH=%PATH%;C:\Program Files (x86)\CMake\bin (红色部分要填写自己cmake安装的路径)

4.跳转到protobuf源码的cmake里,创建build目录 ,在build下创建solution文件

cd  protobuf/cmake

mkdir build & cd build

mkdir solution & cd solution

5.生成vs解决方案

32位:cmake -G "Visual Studio 14 2015" -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=../../../../install ../../

64位:cmake -G "Visual Studio 14 2015 Win64" -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=../../../../install ../../

6.到sulution目录下找到protobuf.sln 打开 ALL_BUILD 生成 。

选择INSTALL 结束之后 在第一步里创建的install下面会有bin include lib 

编译vs2015 protobuf

其中问题:

第5步的时候,如果不添加 -Dprotobuf_BUILD_TESTS=OFF 会报错,这里单元测试不需要就加上这个,

If the *gmock* directory does not exist, and you do not want to build protobuf unit tests,
you need to add *cmake* command argument `-Dprotobuf_BUILD_TESTS=OFF` to disable testing.

如果需要test的话应该需要zlib 之类的其他依赖,参照readme.md 自己去研究一下,我这里不需要就省事了。

相关文章: