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