This directory contains *CMake* files that can be used to build protobuf.
You need to have [CMake](http://www.cmake.org),
[Git](http://git-scm.com), and [Abseil](https://github.com/abseil/abseil-cpp)
installed on your computer before proceeding. We currently support CMake 3.5
and newer on both [Windows](#windows-builds) and [Linux](#linux-builds).
Most of the instructions will be given using CMake's command-line interface, but
the same actions can be performed using appropriate GUI tools.
# CMake Flags
## C++ Version
By default, CMake will use whatever C++ version is the system default. Since
protobuf requires C++14 or newer, sometimes you will need to explicitly override
this. For example, the following:
cmake . -DCMAKE_CXX_STANDARD=14
cmake --build
will build protobuf using C++14 (see [CXX_STANDARD](https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html#prop_tgt:CXX_STANDARD){.external} for all available options).
# Windows Builds
On Windows, you can build the project from *Command Prompt* and using an
*Visual Studio* IDE. You will also need to have
[Visual Studio](https://www.visualstudio.com) installed on your computer before
proceeding.
## Environment Setup
Open the appropriate *Command Prompt* from the *Start* menu.
For example *x86 Native Tools Command Prompt for VS 2019*:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional>
Change to your working directory:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional>cd C:\Path\to
C:\Path\to>
Where *C:\Path\to* is path to your real working directory.
Create a folder where protobuf headers/libraries/binaries will be installed after built:
C:\Path\to>mkdir install
If *cmake* command is not available from *Command Prompt*, add it to system *PATH* variable:
C:\Path\to>set PATH=%PATH%;C:\Program Files (x86)\CMake\bin
If *git* command is not available from *Command Prompt*, add it to system *PATH* variable:
C:\Path\to>set PATH=%PATH%;C:\Program Files\Git\cmd
Optionally, you will want to download [ninja](https://ninja-build.org/) and add it to your *PATH* variable.
C:\Path\to>set PATH=%PATH%;C:\tools\ninja
Good. Now you are ready to continue.
## Getting Sources
You can get the latest stable source packages from the release page:
https://github.com/protocolbuffers/protobuf/releases/latest
Or you can use git to clone from protobuf git repository.
C:\Path\to> mkdir src & cd src
C:\Path\to\src> git clone -b [release_tag] https://github.com/protocolbuffers/protobuf.git
Where *[release_tag]* is a git tag like *v3.0.0-beta-1* or a branch name like *main*
if you want to get the latest code.
Go to the project folder:
C:\Path\to\src> cd protobuf
C:\Path\to\src\protobuf>
Remember to update any submodules if you are using git clone (you can skip this
step if you are using a release .tar.gz or .zip package):
```console
C:\Path\to\src\protobuf> git submodule update --init --recursive
```
Good. Now you are ready for *CMake* configuration.
## CMake Configuration
*CMake* supports a lot of different
[generators](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html)
for various native build systems.
Of most interest to Windows programmers are the following:
* [Visual Studio](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators)
This generates a Visual Studio solution for the project.
* [Ninja](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#ninja-generator)
This uses the external tool [Ninja](https://ninja-build.org/) to build. It is the fastest solution available.
Note that as of Visual Studio 2015, Visual Studio includes
[support for opening directly CMake-based projects](https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio).
It is considered good practice not to build CMake projects in the source tree but in a separate folder.
Create a temporary *build* folder and change your working directory to it:
mkdir C:\Path\to\build\protobuf
cd C:\Path\to\build\protobuf
C:\Path\to\build\protobuf>
During configuration you will also be specifying where CMake should expect to
find your Abseil installation. To do so, first set `-Dprotobuf_ABSL_PROVIDER=package`
and then set `-DCMAKE_PREFIX_PATH` to the path where you installed Abseil.
For example:
```console
C:\Path\to\build\protobuf> cmake -S. -Bcmake-out \
-DCMAKE_INSTALL_PREFIX=/tmp/protobuf \
-DCMAKE_CXX_STANDARD=14 \
-Dprotobuf_ABSL_PROVIDER=package \
-DCMAKE_PREFIX_PATH=/tmp/absl # Path to where I installed Abseil
```
The *Makefile* and *Ninja* generators can build the project in only one configuration, so you need to build
a separate folder for each configuration.
To use *Debug* configuration using *Ninja*:
C:\Path\to\build\protobuf>mkdir debug & cd debug
C:\Path\to\build\protobuf\debug>cmake -G "Ninja" ^
-DCMAKE_BUILD_TYPE=Debug ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
C:\Path\to\src\protobuf
It will generate *Ninja* build scripts in current directory.
The *Visual Studio* generator is multi-configuration: it will generate a single *.sln* file that can be used for both *Debug* and *Release*:
C:\Path\to\build\protobuf>mkdir solution & cd solution
C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
C:\Path\to\src\protobuf
It will generate *Visual Studio* solution file *protobuf.sln* in current directory.
### Unit Tests
Unit tests are being built along with the rest of protobuf. The unit tests require Google Mock (now a part of Google Test).
A copy of [Google Test](https://github.com/google/googletest) is included as a Git submodule in the `third-party/googletest` folder.
(You do need to initialize the Git submodules as explained above.)
Alternately, you may want to use protobuf in a larger set-up, you may want to use that standard CMake approach where
you build and install a shared copy of Google Test.
After you've built and installed your Google Test copy, you need add the following definition to your *cmake* command line
during the configuration step: `-Dprotobuf_USE_EXTERNAL_GTEST=ON`.
This will cause the standard CMake `find_package(GTest REQUIRED)` to be used.
[find_package](https://cmake.org/cmake/help/latest/command/find_package.html) will search in a default location,
which on Windows is *C:\Program Files*. This is most likely not what you want. You will want instead to search for
Google Test in your project's root directory (i.e. the same directory you've passed to `CMAKE_INSTALL_PREFIX` when
building Google Test). For this, you need to set the `CMAKE_PREFIX_PATH` CMake variable. (There are other ways in CMake,
see the [manual](https://cmake.org/cmake/help/latest/command/find_package.html) for details.)
For example:
C:\Path\to\build\protobuf>mkdir solution & cd solution
C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
-DCMAKE_PREFIX_PATH=C:\Path\to\my_big_project ^
-Dprotobuf_USE_EXTERNAL_GTEST=ON ^
C:\Path\to\src\protobuf
In most cases, `CMAKE_PREFIX_PATH` and `CMAKE_INSTALL_PREFIX` will point to the same directory.
To disable testing completely, you need to add the following argument to you *cmake* command line: `-Dprotobuf_BUILD_TESTS=OFF`.
For example:
C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
-Dprotobuf_BUILD_TESTS=OFF ^
C:\Path\to\src\protobuf
## Compiling
The standard way to compile a *CMake* project is `cmake --build <directory>`.
Note that if your generator supports multiple configurations, you will probably want to specify which one to build:
cmake --build C:\Path\to\build
protobuf-23.3最新版本
需积分: 0 201 浏览量
更新于2023-06-19
收藏 6.72MB ZIP 举报
**protobuf-23.3最新版本详解**
protobuf(Protocol Buffers)是Google开发的一种数据序列化协议,它允许开发者定义数据结构,然后将结构化的数据序列化为二进制流,便于存储、通信或者在网络上传输。protobuf的核心理念是提供一种高效、灵活且易于解析的数据表示方式,适用于各种编程语言,包括C++、Java、Python等。
在protobuf-23.3这个版本中,我们可以期待一些新的特性、改进和修复的bug。尽管具体的更新日志没有给出,但通常新版本会带来以下几方面的提升:
1. **性能优化**:protobuf的每个新版本都会对序列化和反序列化速度进行优化,使得数据处理更快。在23.3版本中,可能有更高效的编码算法或内存管理策略,从而提高整体性能。
2. **API改进**:新版本可能会引入更简洁、更符合编程习惯的API设计,以提高开发者的开发效率和代码可读性。例如,增加新的构造函数、方法或类,简化了接口,使得与protobuf交互更加方便。
3. **兼容性增强**:protobuf的一个关键特性是向后兼容,新版本通常能正确解析旧版本生成的序列化数据。在23.3版本中,谷歌可能会进一步强化这种兼容性,确保升级到新版本不会导致数据丢失或解析错误。
4. **错误处理和调试**:新版本可能包含了更详细的错误信息和更好的调试支持,帮助开发者快速定位和解决问题。这可能包括新的日志记录选项、更好的异常处理机制或者新增的诊断工具。
5. **语言支持**:protobuf支持多种编程语言,23.3版本可能会对特定语言的SDK进行更新,添加新特性或改进现有功能,如Python的异步支持、Java的流式API等。
6. **新功能**:可能引入了新的数据类型或消息结构,比如枚举类型的扩展、支持元数据注解等,以满足更复杂的应用场景需求。
7. **国际化和本地化**:对于多语言应用,protobuf可能会在新版本中优化字符串处理,支持Unicode和国际化字符集,使得跨地域、跨语言的数据交换更加顺畅。
8. **代码生成工具改进**:protobuf的代码生成工具protoc也可能得到改进,例如支持更多的自定义插件、生成更优雅的代码结构,或者增加了生成文档的功能。
9. **社区支持和文档**:新版本通常会伴随着更完善的文档和社区支持,使得开发者能够更容易地学习和使用protobuf。
要使用protobuf-23.3,你需要下载对应的SDK,根据项目需求编写.proto文件定义数据结构,然后使用protoc编译器生成目标语言的源代码。这些源代码可以被集成到你的应用程序中,用于序列化和反序列化数据。在实际应用中,protobuf常用于构建分布式系统、网络通信、数据库存储等领域。
protobuf-23.3作为一个最新的protobuf版本,旨在提供更高效、稳定和易用的数据序列化解决方案,帮助开发者构建高性能、跨平台的应用程序。如果你的项目依赖protobuf,那么升级到23.3版本将有助于你利用最新的特性和优化,提升项目的整体质量。

Jasonyeahjk
- 粉丝: 0
最新资源
- 创业项目电子商务网站看书网书店建设策划方案.doc
- sparkmlib算法使用有代码输入输出.docx
- 第一章电子商务概述最新版本.ppt
- 2023年FTP服务器配置实验报告.doc
- 2023年信管系统集成项目管理师各章节重点知识点总结精华版.doc
- 2023年算法设计与分析实验报告完整版.doc
- 博科生物医用冷链系统安全解决方案.pptx
- ACCESS酒店管理信息系统简约版.doc
- 2023年IT前景网络工程师规划之路.doc
- 大学计算机基础第5章.pptx
- Hadoop-总体概述ppt课件.ppt
- 2023年河北省计算机对口招生考试试题带部分答案.doc
- HCi我国卫生信息化现状与工作进展报告卫生部办公厅副主任吴琦ppt课件.ppt
- excel学习计划模板.docx
- 2022谈谈医药分销企业管理会计信息化创建.docx
- 按摩店开发小程序功能需求.pdf