欢迎光临
我们一直在努力

Protobuf的安装

编译

参考https://github.com/google/protobuf/blob/master/cmake/README.md

  1. 需要cmake, git, vs
  2. Native Tools Command Prompt
  1. %comspec% /k "d:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat"
  1. 下载https://github.com/google/protobuf/releases中的protobuf-cpp-3.5.0.zip
  2. 解压,cmd进入目录
  1. E:\LIBS\Protobuf\protobuf-3.5.0
  2. E:
  3. mkdir install
  1. 确认环境中有cmake和bit,如果没有
  1. If cmake command is not available from Command Prompt, add it to system PATH variable:
  2. C:\Path\to>set PATH=%PATH%;C:\Program Files (x86)\CMake\bin
  3. If git command is not available from Command Prompt, add it to system PATH variable:
  4. C:\Path\to>set PATH=%PATH%;C:\Program Files\Git\cmd
  1. 开始cmake,下面命令执行后会看到Makefile文件
  1. cd cmake
  2. mkdir build & cd build
  3. ;make release
  4. mkdir release & cd release
  5. cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../../../install ../..
  6. ;make debug(跳回上层build目录)
  7. mkdir debug & cd debug
  8. cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../../../install ../..
  9. ;To create Visual Studio solution file:
  10. mkdir solution & cd solution
  11. ;如果出现问题,说不存在可以用cmake --help看看是否支持。不支持高版本的vs,就要升级cmake了。
  12. ;cmake -G "Visual Studio 12 2013 Win64" -DCMAKE_INSTALL_PREFIX=../../../../install ../..
  13. cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=../../../../install ../..
  1. 7. 编译

打开protobuf.sln选择release还是debug,右键解决方案—->生成解决方案

  1. 生成INSTALL—会在最外层的install文件夹生成结果E:/LIBS/Protobuf/install

    在解决方案里右键INSTALL生成

  1. This will create the following folders under the install location:
  2. bin - that contains protobuf protoc.exe compiler;
  3. include - that contains C++ headers and protobuf *.proto files;
  4. lib - that contains linking libraries and CMake configuration files for protobuf package.

使用

  1. cd F:\MyPrivateProjects\Git\LearnCpp\LearnProtobuf\LearnProtobuf
  2. F:
  3. F:\MyPrivateProjects\Git\LearnCpp\LearnProtobuf\LearnProtobuf\google\bin\protoc.exe
  4. protoc.exe --cpp_out=addressbook/ addressbook.proto
  1. --cpp_out
  2. --java_out
  3. --python_out
  4. --javanano_out
  5. --php_out
  6. --ruby_out
  7. --csharp_out
  8. --objc_out
  9. --js_out
赞(0)
未经允许不得转载:小明编程 » Protobuf的安装

评论 抢沙发