Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 1 | Protocol Buffers - Google's data interchange format |
| 2 | =================================================== |
| 3 | |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 4 | Copyright 2008 Google Inc. |
| 5 | |
| 6 | https://developers.google.com/protocol-buffers/ |
| 7 | |
| 8 | C++ Installation - Unix |
| 9 | ----------------------- |
| 10 | |
| 11 | To build protobuf from source, the following tools are needed: |
| 12 | |
| 13 | * autoconf |
| 14 | * automake |
| 15 | * libtool |
beardedn5rd | b12f630 | 2016-05-06 14:49:52 +0200 | [diff] [blame] | 16 | * make |
beardedn5rd | 2eb774e | 2016-05-06 22:47:17 +0200 | [diff] [blame] | 17 | * g++ |
beardedn5rd | b12f630 | 2016-05-06 14:49:52 +0200 | [diff] [blame] | 18 | * unzip |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 19 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 20 | On Ubuntu/Debian, you can install them with: |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 21 | |
NexusNull | 5142e36 | 2021-10-09 20:42:59 +0200 | [diff] [blame] | 22 | sudo apt-get install autoconf automake libtool curl make g++ unzip |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 23 | |
| 24 | On other platforms, please use the corresponding package managing tool to |
| 25 | install them before proceeding. |
| 26 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 27 | To get the source, download one of the release .tar.gz or .zip packages in the |
| 28 | release page: |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 29 | |
Feng Xiao | afe98de | 2018-08-22 11:55:30 -0700 | [diff] [blame] | 30 | https://github.com/protocolbuffers/protobuf/releases/latest |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 31 | |
| 32 | For example: if you only need C++, download `protobuf-cpp-[VERSION].tar.gz`; if |
| 33 | you need C++ and Java, download `protobuf-java-[VERSION].tar.gz` (every package |
| 34 | contains C++ source already); if you need C++ and multiple other languages, |
| 35 | download `protobuf-all-[VERSION].tar.gz`. |
| 36 | |
| 37 | You can also get the source by "git clone" our git repository. Make sure you |
| 38 | have also cloned the submodules and generated the configure script (skip this |
| 39 | if you are using a release .tar.gz or .zip package): |
| 40 | |
John D. Pope | c5fb586 | 2019-07-05 10:35:51 +1000 | [diff] [blame] | 41 | git clone https://github.com/protocolbuffers/protobuf.git |
| 42 | cd protobuf |
| 43 | git submodule update --init --recursive |
| 44 | ./autogen.sh |
Nick Presta | 75553e9 | 2020-04-27 15:27:37 -0400 | [diff] [blame] | 45 | |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 46 | To build and install the C++ Protocol Buffer runtime and the Protocol |
| 47 | Buffer compiler (protoc) execute the following: |
| 48 | |
Nick Presta | 75553e9 | 2020-04-27 15:27:37 -0400 | [diff] [blame] | 49 | |
John D. Pope | c5fb586 | 2019-07-05 10:35:51 +1000 | [diff] [blame] | 50 | ./configure |
Amin Vakil | f96050a | 2022-01-12 23:43:13 +0330 | [diff] [blame] | 51 | make -j$(nproc) # $(nproc) ensures it uses all cores for compilation |
John D. Pope | c5fb586 | 2019-07-05 10:35:51 +1000 | [diff] [blame] | 52 | make check |
| 53 | sudo make install |
| 54 | sudo ldconfig # refresh shared library cache. |
Nick Presta | 75553e9 | 2020-04-27 15:27:37 -0400 | [diff] [blame] | 55 | |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 56 | If "make check" fails, you can still install, but it is likely that |
| 57 | some features of this library will not work correctly on your system. |
| 58 | Proceed at your own risk. |
| 59 | |
| 60 | For advanced usage information on configure and make, please refer to the |
| 61 | autoconf documentation: |
| 62 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 63 | http://www.gnu.org/software/autoconf/manual/autoconf.html#Running-configure-Scripts |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 64 | |
| 65 | **Hint on install location** |
| 66 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 67 | By default, the package will be installed to /usr/local. However, |
| 68 | on many platforms, /usr/local/lib is not part of LD_LIBRARY_PATH. |
| 69 | You can add it, but it may be easier to just install to /usr |
| 70 | instead. To do this, invoke configure as follows: |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 71 | |
| 72 | ./configure --prefix=/usr |
| 73 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 74 | If you already built the package with a different prefix, make sure |
| 75 | to run "make clean" before building again. |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 76 | |
| 77 | **Compiling dependent packages** |
| 78 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 79 | To compile a package that uses Protocol Buffers, you need to pass |
| 80 | various flags to your compiler and linker. As of version 2.2.0, |
| 81 | Protocol Buffers integrates with pkg-config to manage this. If you |
| 82 | have pkg-config installed, then you can invoke it to get a list of |
| 83 | flags like so: |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 84 | |
John D. Pope | c5fb586 | 2019-07-05 10:35:51 +1000 | [diff] [blame] | 85 | |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 86 | pkg-config --cflags protobuf # print compiler flags |
| 87 | pkg-config --libs protobuf # print linker flags |
| 88 | pkg-config --cflags --libs protobuf # print both |
| 89 | |
John D. Pope | c5fb586 | 2019-07-05 10:35:51 +1000 | [diff] [blame] | 90 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 91 | For example: |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 92 | |
| 93 | c++ my_program.cc my_proto.pb.cc `pkg-config --cflags --libs protobuf` |
| 94 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 95 | Note that packages written prior to the 2.2.0 release of Protocol |
| 96 | Buffers may not yet integrate with pkg-config to get flags, and may |
| 97 | not pass the correct set of flags to correctly link against |
| 98 | libprotobuf. If the package in question uses autoconf, you can |
| 99 | often fix the problem by invoking its configure script like: |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 100 | |
John D. Pope | c5fb586 | 2019-07-05 10:35:51 +1000 | [diff] [blame] | 101 | |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 102 | configure CXXFLAGS="$(pkg-config --cflags protobuf)" \ |
| 103 | LIBS="$(pkg-config --libs protobuf)" |
| 104 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 105 | This will force it to use the correct flags. |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 106 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 107 | If you are writing an autoconf-based package that uses Protocol |
| 108 | Buffers, you should probably use the PKG_CHECK_MODULES macro in your |
| 109 | configure script like: |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 110 | |
| 111 | PKG_CHECK_MODULES([protobuf], [protobuf]) |
| 112 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 113 | See the pkg-config man page for more info. |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 114 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 115 | If you only want protobuf-lite, substitute "protobuf-lite" in place |
| 116 | of "protobuf" in these examples. |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 117 | |
| 118 | **Note for Mac users** |
| 119 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 120 | For a Mac system, Unix tools are not available by default. You will first need |
| 121 | to install Xcode from the Mac AppStore and then run the following command from |
| 122 | a terminal: |
Nick Presta | 75553e9 | 2020-04-27 15:27:37 -0400 | [diff] [blame] | 123 | |
John D. Pope | c5fb586 | 2019-07-05 10:35:51 +1000 | [diff] [blame] | 124 | sudo xcode-select --install |
Nick Presta | 75553e9 | 2020-04-27 15:27:37 -0400 | [diff] [blame] | 125 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 126 | To install Unix tools, you can install "port" following the instructions at |
| 127 | https://www.macports.org . This will reside in /opt/local/bin/port for most |
| 128 | Mac installations. |
Nick Presta | 75553e9 | 2020-04-27 15:27:37 -0400 | [diff] [blame] | 129 | |
John D. Pope | c5fb586 | 2019-07-05 10:35:51 +1000 | [diff] [blame] | 130 | sudo /opt/local/bin/port install autoconf automake libtool |
Nick Presta | 75553e9 | 2020-04-27 15:27:37 -0400 | [diff] [blame] | 131 | |
Jason Lunn | 557f6fb | 2022-03-16 13:48:15 -0400 | [diff] [blame] | 132 | Alternative for Homebrew users: |
| 133 | |
Adam Cozzette | 85eb57d | 2022-03-17 09:12:51 -0700 | [diff] [blame] | 134 | brew install autoconf automake libtool |
Jason Lunn | 557f6fb | 2022-03-16 13:48:15 -0400 | [diff] [blame] | 135 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 136 | Then follow the Unix instructions above. |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 137 | |
| 138 | **Note for cross-compiling** |
| 139 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 140 | The makefiles normally invoke the protoc executable that they just |
| 141 | built in order to build tests. When cross-compiling, the protoc |
| 142 | executable may not be executable on the host machine. In this case, |
| 143 | you must build a copy of protoc for the host machine first, then use |
| 144 | the --with-protoc option to tell configure to use it instead. For |
| 145 | example: |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 146 | |
| 147 | ./configure --with-protoc=protoc |
| 148 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 149 | This will use the installed protoc (found in your $PATH) instead of |
| 150 | trying to execute the one built during the build process. You can |
| 151 | also use an executable that hasn't been installed. For example, if |
| 152 | you built the protobuf package for your host machine in ../host, |
| 153 | you might do: |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 154 | |
| 155 | ./configure --with-protoc=../host/src/protoc |
| 156 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 157 | Either way, you must make sure that the protoc executable you use |
| 158 | has the same version as the protobuf source code you are trying to |
| 159 | use it with. |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 160 | |
| 161 | **Note for Solaris users** |
| 162 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 163 | Solaris 10 x86 has a bug that will make linking fail, complaining |
| 164 | about libstdc++.la being invalid. We have included a work-around |
| 165 | in this package. To use the work-around, run configure as follows: |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 166 | |
| 167 | ./configure LDFLAGS=-L$PWD/src/solaris |
| 168 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 169 | See src/solaris/libstdc++.la for more info on this bug. |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 170 | |
| 171 | **Note for HP C++ Tru64 users** |
| 172 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 173 | To compile invoke configure as follows: |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 174 | |
| 175 | ./configure CXXFLAGS="-O -std ansi -ieee -D__USE_STD_IOSTREAM" |
| 176 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 177 | Also, you will need to use gmake instead of make. |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 178 | |
| 179 | **Note for AIX users** |
| 180 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 181 | Compile using the IBM xlC C++ compiler as follows: |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 182 | |
| 183 | ./configure CXX=xlC |
| 184 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 185 | Also, you will need to use GNU `make` (`gmake`) instead of AIX `make`. |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 186 | |
| 187 | C++ Installation - Windows |
| 188 | -------------------------- |
| 189 | |
| 190 | If you only need the protoc binary, you can download it from the release |
| 191 | page: |
| 192 | |
Feng Xiao | afe98de | 2018-08-22 11:55:30 -0700 | [diff] [blame] | 193 | https://github.com/protocolbuffers/protobuf/releases/latest |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 194 | |
| 195 | In the downloads section, download the zip file protoc-$VERSION-win32.zip. |
| 196 | It contains the protoc binary as well as public proto files of protobuf |
| 197 | library. |
| 198 | |
Robert Schumacher | aaf41c6 | 2017-10-31 04:00:18 -0700 | [diff] [blame] | 199 | Protobuf and its dependencies can be installed directly by using `vcpkg`: |
| 200 | |
| 201 | >vcpkg install protobuf protobuf:x64-windows |
| 202 | |
| 203 | If zlib support is desired, you'll also need to install the zlib feature: |
| 204 | |
| 205 | >vcpkg install protobuf[zlib] protobuf[zlib]:x64-windows |
| 206 | |
| 207 | See https://github.com/Microsoft/vcpkg for more information. |
| 208 | |
Mahmut Ali Ă–ZKURAN | 9b3357d | 2016-05-06 10:16:28 +0300 | [diff] [blame] | 209 | To build from source using Microsoft Visual C++, see [cmake/README.md](../cmake/README.md). |
Feng Xiao | d0e0114 | 2016-01-21 17:06:38 -0800 | [diff] [blame] | 210 | |
| 211 | To build from source using Cygwin or MinGW, follow the Unix installation |
| 212 | instructions, above. |
| 213 | |
| 214 | Binary Compatibility Warning |
| 215 | ---------------------------- |
| 216 | |
| 217 | Due to the nature of C++, it is unlikely that any two versions of the |
| 218 | Protocol Buffers C++ runtime libraries will have compatible ABIs. |
| 219 | That is, if you linked an executable against an older version of |
| 220 | libprotobuf, it is unlikely to work with a newer version without |
| 221 | re-compiling. This problem, when it occurs, will normally be detected |
| 222 | immediately on startup of your app. Still, you may want to consider |
| 223 | using static linkage. You can configure this package to install |
| 224 | static libraries only using: |
| 225 | |
| 226 | ./configure --disable-shared |
| 227 | |
| 228 | Usage |
| 229 | ----- |
| 230 | |
| 231 | The complete documentation for Protocol Buffers is available via the |
| 232 | web at: |
| 233 | |
Josh Kelley | 8aaf4d2 | 2021-05-17 17:53:27 -0400 | [diff] [blame] | 234 | https://developers.google.com/protocol-buffers/ |