blob: 78d6bb5ec72c7a3ec66b39749c8e2aa9bffe3e07 [file] [log] [blame] [view]
Feng Xiaod0e01142016-01-21 17:06:38 -08001Protocol Buffers - Google's data interchange format
2===================================================
3
Feng Xiaob4646ec2018-08-13 14:53:27 -07004[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-cpp_distcheck.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fcpp_distcheck%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-bazel.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fbazel%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fcpp%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-cpp_distcheck.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fcpp_distcheck%2Fcontinuous) [![Build status](https://ci.appveyor.com/api/projects/status/73ctee6ua4w2ruin?svg=true)](https://ci.appveyor.com/project/protobuf/protobuf)
Feng Xiaod0e01142016-01-21 17:06:38 -08005
6Copyright 2008 Google Inc.
7
8https://developers.google.com/protocol-buffers/
9
10C++ Installation - Unix
11-----------------------
12
13To build protobuf from source, the following tools are needed:
14
15 * autoconf
16 * automake
17 * libtool
beardedn5rdb12f6302016-05-06 14:49:52 +020018 * make
beardedn5rd2eb774e2016-05-06 22:47:17 +020019 * g++
beardedn5rdb12f6302016-05-06 14:49:52 +020020 * unzip
Feng Xiaod0e01142016-01-21 17:06:38 -080021
Feng Xiao014e76e2018-03-29 12:11:50 -070022On Ubuntu/Debian, you can install them with:
Feng Xiaod0e01142016-01-21 17:06:38 -080023
Brent Shafferf8a969d2016-06-09 10:36:21 -070024 $ sudo apt-get install autoconf automake libtool curl make g++ unzip
Feng Xiaod0e01142016-01-21 17:06:38 -080025
26On other platforms, please use the corresponding package managing tool to
27install them before proceeding.
28
Feng Xiao014e76e2018-03-29 12:11:50 -070029To get the source, download one of the release .tar.gz or .zip packages in the
30release page:
Feng Xiaod0e01142016-01-21 17:06:38 -080031
Feng Xiaoafe98de2018-08-22 11:55:30 -070032 https://github.com/protocolbuffers/protobuf/releases/latest
Feng Xiao014e76e2018-03-29 12:11:50 -070033
34For example: if you only need C++, download `protobuf-cpp-[VERSION].tar.gz`; if
35you need C++ and Java, download `protobuf-java-[VERSION].tar.gz` (every package
36contains C++ source already); if you need C++ and multiple other languages,
37download `protobuf-all-[VERSION].tar.gz`.
38
39You can also get the source by "git clone" our git repository. Make sure you
40have also cloned the submodules and generated the configure script (skip this
41if you are using a release .tar.gz or .zip package):
42
John D. Popec5fb5862019-07-05 10:35:51 +100043 git clone https://github.com/protocolbuffers/protobuf.git
44 cd protobuf
45 git submodule update --init --recursive
46 ./autogen.sh
Nick Presta75553e92020-04-27 15:27:37 -040047
Feng Xiaod0e01142016-01-21 17:06:38 -080048To build and install the C++ Protocol Buffer runtime and the Protocol
49Buffer compiler (protoc) execute the following:
50
Nick Presta75553e92020-04-27 15:27:37 -040051
John D. Popec5fb5862019-07-05 10:35:51 +100052 ./configure
53 make
54 make check
55 sudo make install
56 sudo ldconfig # refresh shared library cache.
Nick Presta75553e92020-04-27 15:27:37 -040057
Feng Xiaod0e01142016-01-21 17:06:38 -080058If "make check" fails, you can still install, but it is likely that
59some features of this library will not work correctly on your system.
60Proceed at your own risk.
61
62For advanced usage information on configure and make, please refer to the
63autoconf documentation:
64
Feng Xiao014e76e2018-03-29 12:11:50 -070065 http://www.gnu.org/software/autoconf/manual/autoconf.html#Running-configure-Scripts
Feng Xiaod0e01142016-01-21 17:06:38 -080066
67**Hint on install location**
68
Feng Xiao014e76e2018-03-29 12:11:50 -070069By default, the package will be installed to /usr/local. However,
70on many platforms, /usr/local/lib is not part of LD_LIBRARY_PATH.
71You can add it, but it may be easier to just install to /usr
72instead. To do this, invoke configure as follows:
Feng Xiaod0e01142016-01-21 17:06:38 -080073
74 ./configure --prefix=/usr
75
Feng Xiao014e76e2018-03-29 12:11:50 -070076If you already built the package with a different prefix, make sure
77to run "make clean" before building again.
Feng Xiaod0e01142016-01-21 17:06:38 -080078
79**Compiling dependent packages**
80
Feng Xiao014e76e2018-03-29 12:11:50 -070081To compile a package that uses Protocol Buffers, you need to pass
82various flags to your compiler and linker. As of version 2.2.0,
83Protocol Buffers integrates with pkg-config to manage this. If you
84have pkg-config installed, then you can invoke it to get a list of
85flags like so:
Feng Xiaod0e01142016-01-21 17:06:38 -080086
John D. Popec5fb5862019-07-05 10:35:51 +100087
Feng Xiaod0e01142016-01-21 17:06:38 -080088 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. Popec5fb5862019-07-05 10:35:51 +100092
Feng Xiao014e76e2018-03-29 12:11:50 -070093For example:
Feng Xiaod0e01142016-01-21 17:06:38 -080094
95 c++ my_program.cc my_proto.pb.cc `pkg-config --cflags --libs protobuf`
96
Feng Xiao014e76e2018-03-29 12:11:50 -070097Note that packages written prior to the 2.2.0 release of Protocol
98Buffers may not yet integrate with pkg-config to get flags, and may
99not pass the correct set of flags to correctly link against
100libprotobuf. If the package in question uses autoconf, you can
101often fix the problem by invoking its configure script like:
Feng Xiaod0e01142016-01-21 17:06:38 -0800102
John D. Popec5fb5862019-07-05 10:35:51 +1000103
Feng Xiaod0e01142016-01-21 17:06:38 -0800104 configure CXXFLAGS="$(pkg-config --cflags protobuf)" \
105 LIBS="$(pkg-config --libs protobuf)"
106
Feng Xiao014e76e2018-03-29 12:11:50 -0700107This will force it to use the correct flags.
Feng Xiaod0e01142016-01-21 17:06:38 -0800108
Feng Xiao014e76e2018-03-29 12:11:50 -0700109If you are writing an autoconf-based package that uses Protocol
110Buffers, you should probably use the PKG_CHECK_MODULES macro in your
111configure script like:
Feng Xiaod0e01142016-01-21 17:06:38 -0800112
113 PKG_CHECK_MODULES([protobuf], [protobuf])
114
Feng Xiao014e76e2018-03-29 12:11:50 -0700115See the pkg-config man page for more info.
Feng Xiaod0e01142016-01-21 17:06:38 -0800116
Feng Xiao014e76e2018-03-29 12:11:50 -0700117If you only want protobuf-lite, substitute "protobuf-lite" in place
118of "protobuf" in these examples.
Feng Xiaod0e01142016-01-21 17:06:38 -0800119
120**Note for Mac users**
121
Feng Xiao014e76e2018-03-29 12:11:50 -0700122For a Mac system, Unix tools are not available by default. You will first need
123to install Xcode from the Mac AppStore and then run the following command from
124a terminal:
Nick Presta75553e92020-04-27 15:27:37 -0400125
John D. Popec5fb5862019-07-05 10:35:51 +1000126 sudo xcode-select --install
Nick Presta75553e92020-04-27 15:27:37 -0400127
Feng Xiao014e76e2018-03-29 12:11:50 -0700128To install Unix tools, you can install "port" following the instructions at
129https://www.macports.org . This will reside in /opt/local/bin/port for most
130Mac installations.
Nick Presta75553e92020-04-27 15:27:37 -0400131
John D. Popec5fb5862019-07-05 10:35:51 +1000132 sudo /opt/local/bin/port install autoconf automake libtool
Nick Presta75553e92020-04-27 15:27:37 -0400133
Feng Xiao014e76e2018-03-29 12:11:50 -0700134Then follow the Unix instructions above.
Feng Xiaod0e01142016-01-21 17:06:38 -0800135
136**Note for cross-compiling**
137
Feng Xiao014e76e2018-03-29 12:11:50 -0700138The makefiles normally invoke the protoc executable that they just
139built in order to build tests. When cross-compiling, the protoc
140executable may not be executable on the host machine. In this case,
141you must build a copy of protoc for the host machine first, then use
142the --with-protoc option to tell configure to use it instead. For
143example:
Feng Xiaod0e01142016-01-21 17:06:38 -0800144
145 ./configure --with-protoc=protoc
146
Feng Xiao014e76e2018-03-29 12:11:50 -0700147This will use the installed protoc (found in your $PATH) instead of
148trying to execute the one built during the build process. You can
149also use an executable that hasn't been installed. For example, if
150you built the protobuf package for your host machine in ../host,
151you might do:
Feng Xiaod0e01142016-01-21 17:06:38 -0800152
153 ./configure --with-protoc=../host/src/protoc
154
Feng Xiao014e76e2018-03-29 12:11:50 -0700155Either way, you must make sure that the protoc executable you use
156has the same version as the protobuf source code you are trying to
157use it with.
Feng Xiaod0e01142016-01-21 17:06:38 -0800158
159**Note for Solaris users**
160
Feng Xiao014e76e2018-03-29 12:11:50 -0700161Solaris 10 x86 has a bug that will make linking fail, complaining
162about libstdc++.la being invalid. We have included a work-around
163in this package. To use the work-around, run configure as follows:
Feng Xiaod0e01142016-01-21 17:06:38 -0800164
165 ./configure LDFLAGS=-L$PWD/src/solaris
166
Feng Xiao014e76e2018-03-29 12:11:50 -0700167See src/solaris/libstdc++.la for more info on this bug.
Feng Xiaod0e01142016-01-21 17:06:38 -0800168
169**Note for HP C++ Tru64 users**
170
Feng Xiao014e76e2018-03-29 12:11:50 -0700171To compile invoke configure as follows:
Feng Xiaod0e01142016-01-21 17:06:38 -0800172
173 ./configure CXXFLAGS="-O -std ansi -ieee -D__USE_STD_IOSTREAM"
174
Feng Xiao014e76e2018-03-29 12:11:50 -0700175Also, you will need to use gmake instead of make.
Feng Xiaod0e01142016-01-21 17:06:38 -0800176
177**Note for AIX users**
178
Feng Xiao014e76e2018-03-29 12:11:50 -0700179Compile using the IBM xlC C++ compiler as follows:
Feng Xiaod0e01142016-01-21 17:06:38 -0800180
181 ./configure CXX=xlC
182
Feng Xiao014e76e2018-03-29 12:11:50 -0700183Also, you will need to use GNU `make` (`gmake`) instead of AIX `make`.
Feng Xiaod0e01142016-01-21 17:06:38 -0800184
185C++ Installation - Windows
186--------------------------
187
188If you only need the protoc binary, you can download it from the release
189page:
190
Feng Xiaoafe98de2018-08-22 11:55:30 -0700191 https://github.com/protocolbuffers/protobuf/releases/latest
Feng Xiaod0e01142016-01-21 17:06:38 -0800192
193In the downloads section, download the zip file protoc-$VERSION-win32.zip.
194It contains the protoc binary as well as public proto files of protobuf
195library.
196
Robert Schumacheraaf41c62017-10-31 04:00:18 -0700197Protobuf and its dependencies can be installed directly by using `vcpkg`:
198
199 >vcpkg install protobuf protobuf:x64-windows
200
201If zlib support is desired, you'll also need to install the zlib feature:
202
203 >vcpkg install protobuf[zlib] protobuf[zlib]:x64-windows
204
205See https://github.com/Microsoft/vcpkg for more information.
206
Mahmut Ali Ă–ZKURAN9b3357d2016-05-06 10:16:28 +0300207To build from source using Microsoft Visual C++, see [cmake/README.md](../cmake/README.md).
Feng Xiaod0e01142016-01-21 17:06:38 -0800208
209To build from source using Cygwin or MinGW, follow the Unix installation
210instructions, above.
211
212Binary Compatibility Warning
213----------------------------
214
215Due to the nature of C++, it is unlikely that any two versions of the
216Protocol Buffers C++ runtime libraries will have compatible ABIs.
217That is, if you linked an executable against an older version of
218libprotobuf, it is unlikely to work with a newer version without
219re-compiling. This problem, when it occurs, will normally be detected
220immediately on startup of your app. Still, you may want to consider
221using static linkage. You can configure this package to install
222static libraries only using:
223
224 ./configure --disable-shared
225
226Usage
227-----
228
229The complete documentation for Protocol Buffers is available via the
230web at:
231
232 https://developers.google.com/protocol-buffers/