<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Protobuf on BoilTask's Blog</title><link>https://boiltask.com/en/tags/protobuf/</link><description>Recent content in Protobuf on BoilTask's Blog</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Sat, 18 Jul 2020 17:39:54 +0000</lastBuildDate><atom:link href="https://boiltask.com/en/tags/protobuf/index.xml" rel="self" type="application/rss+xml"/><item><title>How to Use C++ Protobuf on Windows</title><link>https://boiltask.com/en/knowledge/cpp/protobuf-windows/</link><pubDate>Sat, 18 Jul 2020 17:39:54 +0000</pubDate><guid>https://boiltask.com/en/knowledge/cpp/protobuf-windows/</guid><description>&lt;p&gt;Refer to the following to configure &lt;code&gt;Protobuf&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a class="link" href="https://github.com/protocolbuffers/protobuf/tree/master/src#c-installation---windows" target="_blank" rel="noopener"&gt;https://github.com/protocolbuffers/protobuf/tree/master/src#c-installation&amp;mdash;windows&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="required-environment"&gt;&lt;a href="#required-environment" class="header-anchor"&gt;&lt;/a&gt;Required Environment
&lt;/h2&gt;&lt;p&gt;It is recommended to install the following environment in advance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Windows 10&lt;/li&gt;
&lt;li&gt;Git&lt;/li&gt;
&lt;li&gt;CMake&lt;/li&gt;
&lt;li&gt;Visual Studio 2019&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="generator-tool"&gt;&lt;a href="#generator-tool" class="header-anchor"&gt;&lt;/a&gt;Generator Tool
&lt;/h2&gt;&lt;p&gt;Download the &lt;code&gt;protobuf&lt;/code&gt; generator tool from &lt;a class="link" href="https://github.com/protocolbuffers/protobuf/releases/latest" target="_blank" rel="noopener"&gt;https://github.com/protocolbuffers/protobuf/releases/latest&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The file should be in the form &lt;code&gt;protoc-$VERSION-win32.zip&lt;/code&gt;; extract &lt;code&gt;bin/protoc.exe&lt;/code&gt; from it and place it under &lt;code&gt;Dep/protobuf/bin&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="build-dependencies"&gt;&lt;a href="#build-dependencies" class="header-anchor"&gt;&lt;/a&gt;Build Dependencies
&lt;/h2&gt;&lt;p&gt;Refer to the following for the dependencies required for compilation:&lt;/p&gt;
&lt;p&gt;&lt;a class="link" href="https://github.com/protocolbuffers/protobuf/blob/master/cmake/README.md" target="_blank" rel="noopener"&gt;https://github.com/protocolbuffers/protobuf/blob/master/cmake/README.md&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Download the &lt;code&gt;protobuf&lt;/code&gt; source files from &lt;a class="link" href="https://github.com/protocolbuffers/protobuf/releases/latest" target="_blank" rel="noopener"&gt;https://github.com/protocolbuffers/protobuf/releases/latest&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The file should be in the form &lt;code&gt;protobuf-cpp-[VERSION].tar.gz&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Extract all files into a folder; here &lt;code&gt;D:\Protobuf&lt;/code&gt; is used as an example.&lt;/p&gt;
&lt;p&gt;Open &lt;code&gt;cmake-gui&lt;/code&gt;; set the &lt;code&gt;source code&lt;/code&gt; folder to &lt;code&gt;D:\Protobuf\cmake&lt;/code&gt; and the &lt;code&gt;build the binaries&lt;/code&gt; folder to the target folder, here using &lt;code&gt;D:\Protobuf-build&lt;/code&gt; as an example.&lt;/p&gt;
&lt;p&gt;Click &lt;code&gt;Configure&lt;/code&gt; and select &lt;code&gt;Visual Studio 2019&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Uncheck all options in the configuration.&lt;/p&gt;
&lt;p&gt;Note the &lt;code&gt;CMAKE_INSTALL_PREFIX&lt;/code&gt; value; this is where the target files will be placed after the install step is run later. Here &lt;code&gt;D:/Protobuf-install&lt;/code&gt; is used as an example.&lt;/p&gt;
&lt;p&gt;Click &lt;code&gt;Generate&lt;/code&gt; to generate the solution, then &lt;code&gt;Open Project&lt;/code&gt; to open the solution.&lt;/p&gt;
&lt;p&gt;Select &lt;code&gt;MinSizeRel&lt;/code&gt; and &lt;code&gt;x64&lt;/code&gt;, then build the solution.&lt;/p&gt;
&lt;p&gt;Right-click &lt;code&gt;INSTALL&lt;/code&gt;, select Build, and the target files will be generated in the folder configured earlier.&lt;/p&gt;
&lt;p&gt;Copy &lt;code&gt;D:/Protobuf-install/include&lt;/code&gt; to the project&amp;rsquo;s &lt;code&gt;/protobuf/include&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Copy &lt;code&gt;D:/Protobuf-install/lib&lt;/code&gt; to the project&amp;rsquo;s &lt;code&gt;/protobuf/lib&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="configure-the-project"&gt;&lt;a href="#configure-the-project" class="header-anchor"&gt;&lt;/a&gt;Configure the Project
&lt;/h2&gt;&lt;p&gt;In a &lt;code&gt;Visual Studio&lt;/code&gt; project, configure &lt;code&gt;Protobuf&lt;/code&gt; as follows.&lt;/p&gt;
&lt;h3 id="configure-header-file-references"&gt;&lt;a href="#configure-header-file-references" class="header-anchor"&gt;&lt;/a&gt;Configure Header File References
&lt;/h3&gt;&lt;p&gt;Right-click the project and open Properties, click &lt;code&gt;C/C++&lt;/code&gt;, and in &lt;code&gt;附加包含目录&lt;/code&gt;, enter the &lt;code&gt;protobuf&lt;/code&gt; header file directory, for example: &lt;code&gt;\protobuf\include&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id="configure-static-linking"&gt;&lt;a href="#configure-static-linking" class="header-anchor"&gt;&lt;/a&gt;Configure Static Linking
&lt;/h3&gt;&lt;p&gt;Right-click the project and open Properties, click &lt;code&gt;链接器&lt;/code&gt;, and in &lt;code&gt;附加库目录&lt;/code&gt;, enter the &lt;code&gt;protobuf&lt;/code&gt; dependency file directory, for example: &lt;code&gt;\protobuf\lib&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Expand the &lt;code&gt;链接器&lt;/code&gt; section, select &lt;code&gt;输入&lt;/code&gt;, and in &lt;code&gt;附加依赖项&lt;/code&gt;, enter the &lt;code&gt;protobuf&lt;/code&gt; dependency file names, such as &lt;code&gt;libprotobuf.lib&lt;/code&gt; and &lt;code&gt;libprotobuf-lite.lib&lt;/code&gt;.&lt;/p&gt;</description></item></channel></rss>