您的位置:首页 > 其它

protobuf3.4在VS2015环境下编译

2017-08-20 11:38 405 查看
1、首先必须保证已下载安装VS2015、Git、CMake。

2、从Github中下载protobuf的压缩包,然后选择一个目录进行解压。

3、然后在解压目录的同级目录新建文件夹install(用于存放头文件/库/二进制文件)。

4、在(解压目录)\cmake目录下创建build目录,进入build目录,创建release、debug、solution三个目录。

5、打开开始面板,点击VS2015文件夹,点击“VS2015 x62 x86兼容工具命令提示符”。

6、编译时要安装gmock,google的单元测试工具,否则后期编译时会报错。cd进入到(解压目录),先创建一个gmock文件夹,然后执行指令git clone -b release-1.7.0 https://github.com/google/googlemock.git gmock

cd进入gmock目录,执行指令git clone -b release-1.7.0 https://github.com/google/googletest.git gtest

老版本的gmock与gtest是分开的,新版本做到了一起。

7、假设我们的解压目录是 C:\Path\to\protobuf,执行下列指令

C:\Path\to\protobuf\gmock>cd ..\cmake\build\release

C:\Path\to\protobuf\cmake\build\release>cmake -G “NMake Makefiles” ^

-DCMAKE_BUILD_TYPE=Release ^

-DCMAKE_INSTALL_PREFIX=../../../../install ^

../..

同样的,进入debug目录执行指令

C:\Path\to\protobuf\cmake\build\debug>cmake -G “NMake Makefiles” ^

-DCMAKE_BUILD_TYPE=Debug ^

-DCMAKE_INSTALL_PREFIX=../../../../install ^

../..

进入solution目录执行

C:\Path\to\protobuf\cmake\build\solution>cmake -G “Visual Studio 12 2013 Win64” ^

-DCMAKE_INSTALL_PREFIX=../../../../install ^

../..

根据你的需要去执行其中一个,当然都执行也可以

前两个是创建makefile文件,后者是生成VS解决方案。

8、编译

C:\Path\to\protobuf\cmake\build\release>nmake

或者

C:\Path\to\protobuf\cmake\build\debug>nmake

也可以通过VS打开项目解决方案,选择debug或release,在生成菜单中选择”Build Solution”.

9、测试

C:\Path\to\protobuf\cmake\build\release>nmake check



C:\Path\to\protobuf\cmake\build\debug>nmake check

也可以通过VS

10、安装

C:\Path\to\protobuf\cmake\build\release>nmake install



C:\Path\to\protobuf\cmake\build\debug>nmake install

成功!!!

11、如果你想在libprotobuf中包含GzipInputStream与GzipOutputStream

(google/protobuf/io/gzip_stream.h),

Make sure zlib’s two headers are in your
C:\Path\to\install\include
path

Make sure zlib’s linking libraries (*.lib file) is in your

C:\Path\to\install\lib
library path.

下载

C:\Path\to>git clone -b v1.2.8 https://github.com/madler/zlib.git

C:\Path\to>cd zlib

编译与安装

C:\Path\to\zlib>mkdir build & cd build

C:\Path\to\zlib\build>mkdir release & cd release

C:\Path\to\zlib\build\release>cmake -G “NMake Makefiles” -DCMAKE_BUILD_TYPE=Release ^

-DCMAKE_INSTALL_PREFIX=../../../install ../..

C:\Path\to\zlib\build\release>nmake & nmake install

当然也可以是debug

12、Now add bin folder from install to system PATH:

C:\Path\to>set PATH=%PATH%;C:\Path\to\install\bin
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  protobuf VS2015编译