windows下编译protobuf的python接口

由于某些原因这种方式安装失败

pip install protobuf

因此只能下载源码编译生成接口
1)到github上下载所需版本的protobuf源码(我下的3.1.0)

2)到这里下载gmock源码,重命名为gmock复制到protobuf/

3)到这里下载gtest源码,重命名为gtest复制到protobuf/gmock/

4)到这里下载cmake安装程序,安装windows版的cmake

5)参考这篇文章,编写脚本build_VS.bat

::参考文章 https://github.com/google/protobuf/blob/master/cmake/README.md
::默认当前操作系统已安装 git 和 cmake,并配置好了环境变量
echo off & color 0A

::设置所需要的Protobuf版本,最新版本可以在github上查到 https://github.com/google/protobuf
::必须与下载的版本一致
set PROTOBUF_VESION="3.1.0"
echo %PROTOBUF_VESION%
set PROTOBUF_PATH="protobuf_%PROTOBUF_VESION%"
echo %PROTOBUF_PATH%
cd %PROTOBUF_PATH%

::设置VS工具集,相当于指定VS版本,取决于VS的安装路径
set VS_DEV_CMD="E:\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat"
::设置工程文件夹名字,用来区分不同的VS版本
set BUILD_PATH="build_VS2013"
::设置编译版本 Debug Or Release
set MODE="Release"


cd cmake
if not exist %BUILD_PATH% md %BUILD_PATH%

cd %BUILD_PATH%
if not exist %MODE% md %MODE%
cd %MODE%

::开始构建和编译
call %VS_DEV_CMD%
cmake ../../ -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=%MODE%
call extract_includes.bat
nmake /f Makefile

echo %cd%
pause

6)将脚本放在protobuf同级目录,双击运行
成功后将 protobuf/cmake/build_VS2013/Release/protoc.exe 复制到 protobuf/python/protoc.exe

7)目录切换到 protobuf/python/

python setup.py install

库文件会自动拷贝到python安装目录


你可能感兴趣的:(C++基础)