blob: cf843d7595fdd6ab963624893f8feb6b0eb771a7 [file] [log] [blame] [view]
Feng Xiaod0e01142016-01-21 17:06:38 -08001Protocol Buffers - Google's data interchange format
2===================================================
3
Feng Xiaod0e01142016-01-21 17:06:38 -08004Copyright 2008 Google Inc.
5
6https://developers.google.com/protocol-buffers/
7
8C++ Installation - Unix
9-----------------------
10
11To build protobuf from source, the following tools are needed:
12
13 * autoconf
14 * automake
15 * libtool
beardedn5rdb12f6302016-05-06 14:49:52 +020016 * make
beardedn5rd2eb774e2016-05-06 22:47:17 +020017 * g++
beardedn5rdb12f6302016-05-06 14:49:52 +020018 * unzip
Feng Xiaod0e01142016-01-21 17:06:38 -080019
Feng Xiao014e76e2018-03-29 12:11:50 -070020On Ubuntu/Debian, you can install them with:
Feng Xiaod0e01142016-01-21 17:06:38 -080021
NexusNull5142e362021-10-09 20:42:59 +020022 sudo apt-get install autoconf automake libtool curl make g++ unzip
Feng Xiaod0e01142016-01-21 17:06:38 -080023
24On other platforms, please use the corresponding package managing tool to
25install them before proceeding.
26
Feng Xiao014e76e2018-03-29 12:11:50 -070027To get the source, download one of the release .tar.gz or .zip packages in the
28release page:
Feng Xiaod0e01142016-01-21 17:06:38 -080029
Feng Xiaoafe98de2018-08-22 11:55:30 -070030 https://github.com/protocolbuffers/protobuf/releases/latest
Feng Xiao014e76e2018-03-29 12:11:50 -070031
32For example: if you only need C++, download `protobuf-cpp-[VERSION].tar.gz`; if
33you need C++ and Java, download `protobuf-java-[VERSION].tar.gz` (every package
34contains C++ source already); if you need C++ and multiple other languages,
35download `protobuf-all-[VERSION].tar.gz`.
36
37You can also get the source by "git clone" our git repository. Make sure you
38have also cloned the submodules and generated the configure script (skip this
39if you are using a release .tar.gz or .zip package):
40
John D. Popec5fb5862019-07-05 10:35:51 +100041 git clone https://github.com/protocolbuffers/protobuf.git
42 cd protobuf
43 git submodule update --init --recursive
44 ./autogen.sh
Nick Presta75553e92020-04-27 15:27:37 -040045
Feng Xiaod0e01142016-01-21 17:06:38 -080046To build and install the C++ Protocol Buffer runtime and the Protocol
47Buffer compiler (protoc) execute the following:
48
Nick Presta75553e92020-04-27 15:27:37 -040049
John D. Popec5fb5862019-07-05 10:35:51 +100050 ./configure
Amin Vakilf96050a2022-01-12 23:43:13 +033051 make -j$(nproc) # $(nproc) ensures it uses all cores for compilation
John D. Popec5fb5862019-07-05 10:35:51 +100052 make check
53 sudo make install
54 sudo ldconfig # refresh shared library cache.
Nick Presta75553e92020-04-27 15:27:37 -040055
Feng Xiaod0e01142016-01-21 17:06:38 -080056If "make check" fails, you can still install, but it is likely that
57some features of this library will not work correctly on your system.
58Proceed at your own risk.
59
60For advanced usage information on configure and make, please refer to the
61autoconf documentation:
62
Feng Xiao014e76e2018-03-29 12:11:50 -070063 http://www.gnu.org/software/autoconf/manual/autoconf.html#Running-configure-Scripts
Feng Xiaod0e01142016-01-21 17:06:38 -080064
65**Hint on install location**
66
Feng Xiao014e76e2018-03-29 12:11:50 -070067By default, the package will be installed to /usr/local. However,
68on many platforms, /usr/local/lib is not part of LD_LIBRARY_PATH.
69You can add it, but it may be easier to just install to /usr
70instead. To do this, invoke configure as follows:
Feng Xiaod0e01142016-01-21 17:06:38 -080071
72 ./configure --prefix=/usr
73
Feng Xiao014e76e2018-03-29 12:11:50 -070074If you already built the package with a different prefix, make sure
75to run "make clean" before building again.
Feng Xiaod0e01142016-01-21 17:06:38 -080076
77**Compiling dependent packages**
78
Feng Xiao014e76e2018-03-29 12:11:50 -070079To compile a package that uses Protocol Buffers, you need to pass
80various flags to your compiler and linker. As of version 2.2.0,
81Protocol Buffers integrates with pkg-config to manage this. If you
82have pkg-config installed, then you can invoke it to get a list of
83flags like so:
Feng Xiaod0e01142016-01-21 17:06:38 -080084
John D. Popec5fb5862019-07-05 10:35:51 +100085
Feng Xiaod0e01142016-01-21 17:06:38 -080086 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. Popec5fb5862019-07-05 10:35:51 +100090
Feng Xiao014e76e2018-03-29 12:11:50 -070091For example:
Feng Xiaod0e01142016-01-21 17:06:38 -080092
93 c++ my_program.cc my_proto.pb.cc `pkg-config --cflags --libs protobuf`
94
Feng Xiao014e76e2018-03-29 12:11:50 -070095Note that packages written prior to the 2.2.0 release of Protocol
96Buffers may not yet integrate with pkg-config to get flags, and may
97not pass the correct set of flags to correctly link against
98libprotobuf. If the package in question uses autoconf, you can
99often fix the problem by invoking its configure script like:
Feng Xiaod0e01142016-01-21 17:06:38 -0800100
John D. Popec5fb5862019-07-05 10:35:51 +1000101
Feng Xiaod0e01142016-01-21 17:06:38 -0800102 configure CXXFLAGS="$(pkg-config --cflags protobuf)" \
103 LIBS="$(pkg-config --libs protobuf)"
104
Feng Xiao014e76e2018-03-29 12:11:50 -0700105This will force it to use the correct flags.
Feng Xiaod0e01142016-01-21 17:06:38 -0800106
Feng Xiao014e76e2018-03-29 12:11:50 -0700107If you are writing an autoconf-based package that uses Protocol
108Buffers, you should probably use the PKG_CHECK_MODULES macro in your
109configure script like:
Feng Xiaod0e01142016-01-21 17:06:38 -0800110
111 PKG_CHECK_MODULES([protobuf], [protobuf])
112
Feng Xiao014e76e2018-03-29 12:11:50 -0700113See the pkg-config man page for more info.
Feng Xiaod0e01142016-01-21 17:06:38 -0800114
Feng Xiao014e76e2018-03-29 12:11:50 -0700115If you only want protobuf-lite, substitute "protobuf-lite" in place
116of "protobuf" in these examples.
Feng Xiaod0e01142016-01-21 17:06:38 -0800117
118**Note for Mac users**
119
Feng Xiao014e76e2018-03-29 12:11:50 -0700120For a Mac system, Unix tools are not available by default. You will first need
121to install Xcode from the Mac AppStore and then run the following command from
122a terminal:
Nick Presta75553e92020-04-27 15:27:37 -0400123
John D. Popec5fb5862019-07-05 10:35:51 +1000124 sudo xcode-select --install
Nick Presta75553e92020-04-27 15:27:37 -0400125
Feng Xiao014e76e2018-03-29 12:11:50 -0700126To install Unix tools, you can install "port" following the instructions at
127https://www.macports.org . This will reside in /opt/local/bin/port for most
128Mac installations.
Nick Presta75553e92020-04-27 15:27:37 -0400129
John D. Popec5fb5862019-07-05 10:35:51 +1000130 sudo /opt/local/bin/port install autoconf automake libtool
Nick Presta75553e92020-04-27 15:27:37 -0400131
Jason Lunn557f6fb2022-03-16 13:48:15 -0400132Alternative for Homebrew users:
133
Adam Cozzette85eb57d2022-03-17 09:12:51 -0700134 brew install autoconf automake libtool
Jason Lunn557f6fb2022-03-16 13:48:15 -0400135
Feng Xiao014e76e2018-03-29 12:11:50 -0700136Then follow the Unix instructions above.
Feng Xiaod0e01142016-01-21 17:06:38 -0800137
138**Note for cross-compiling**
139
Feng Xiao014e76e2018-03-29 12:11:50 -0700140The makefiles normally invoke the protoc executable that they just
141built in order to build tests. When cross-compiling, the protoc
142executable may not be executable on the host machine. In this case,
143you must build a copy of protoc for the host machine first, then use
144the --with-protoc option to tell configure to use it instead. For
145example:
Feng Xiaod0e01142016-01-21 17:06:38 -0800146
147 ./configure --with-protoc=protoc
148
Feng Xiao014e76e2018-03-29 12:11:50 -0700149This will use the installed protoc (found in your $PATH) instead of
150trying to execute the one built during the build process. You can
151also use an executable that hasn't been installed. For example, if
152you built the protobuf package for your host machine in ../host,
153you might do:
Feng Xiaod0e01142016-01-21 17:06:38 -0800154
155 ./configure --with-protoc=../host/src/protoc
156
Feng Xiao014e76e2018-03-29 12:11:50 -0700157Either way, you must make sure that the protoc executable you use
158has the same version as the protobuf source code you are trying to
159use it with.
Feng Xiaod0e01142016-01-21 17:06:38 -0800160
161**Note for Solaris users**
162
Feng Xiao014e76e2018-03-29 12:11:50 -0700163Solaris 10 x86 has a bug that will make linking fail, complaining
164about libstdc++.la being invalid. We have included a work-around
165in this package. To use the work-around, run configure as follows:
Feng Xiaod0e01142016-01-21 17:06:38 -0800166
167 ./configure LDFLAGS=-L$PWD/src/solaris
168
Feng Xiao014e76e2018-03-29 12:11:50 -0700169See src/solaris/libstdc++.la for more info on this bug.
Feng Xiaod0e01142016-01-21 17:06:38 -0800170
171**Note for HP C++ Tru64 users**
172
Feng Xiao014e76e2018-03-29 12:11:50 -0700173To compile invoke configure as follows:
Feng Xiaod0e01142016-01-21 17:06:38 -0800174
175 ./configure CXXFLAGS="-O -std ansi -ieee -D__USE_STD_IOSTREAM"
176
Feng Xiao014e76e2018-03-29 12:11:50 -0700177Also, you will need to use gmake instead of make.
Feng Xiaod0e01142016-01-21 17:06:38 -0800178
179**Note for AIX users**
180
Feng Xiao014e76e2018-03-29 12:11:50 -0700181Compile using the IBM xlC C++ compiler as follows:
Feng Xiaod0e01142016-01-21 17:06:38 -0800182
183 ./configure CXX=xlC
184
Feng Xiao014e76e2018-03-29 12:11:50 -0700185Also, you will need to use GNU `make` (`gmake`) instead of AIX `make`.
Feng Xiaod0e01142016-01-21 17:06:38 -0800186
187C++ Installation - Windows
188--------------------------
189
190If you only need the protoc binary, you can download it from the release
191page:
192
Feng Xiaoafe98de2018-08-22 11:55:30 -0700193 https://github.com/protocolbuffers/protobuf/releases/latest
Feng Xiaod0e01142016-01-21 17:06:38 -0800194
195In the downloads section, download the zip file protoc-$VERSION-win32.zip.
196It contains the protoc binary as well as public proto files of protobuf
197library.
198
Robert Schumacheraaf41c62017-10-31 04:00:18 -0700199Protobuf and its dependencies can be installed directly by using `vcpkg`:
200
201 >vcpkg install protobuf protobuf:x64-windows
202
203If zlib support is desired, you'll also need to install the zlib feature:
204
205 >vcpkg install protobuf[zlib] protobuf[zlib]:x64-windows
206
207See https://github.com/Microsoft/vcpkg for more information.
208
Mahmut Ali Ă–ZKURAN9b3357d2016-05-06 10:16:28 +0300209To build from source using Microsoft Visual C++, see [cmake/README.md](../cmake/README.md).
Feng Xiaod0e01142016-01-21 17:06:38 -0800210
211To build from source using Cygwin or MinGW, follow the Unix installation
212instructions, above.
213
214Binary Compatibility Warning
215----------------------------
216
217Due to the nature of C++, it is unlikely that any two versions of the
218Protocol Buffers C++ runtime libraries will have compatible ABIs.
219That is, if you linked an executable against an older version of
220libprotobuf, it is unlikely to work with a newer version without
221re-compiling. This problem, when it occurs, will normally be detected
222immediately on startup of your app. Still, you may want to consider
223using static linkage. You can configure this package to install
224static libraries only using:
225
226 ./configure --disable-shared
227
228Usage
229-----
230
231The complete documentation for Protocol Buffers is available via the
232web at:
233
Josh Kelley8aaf4d22021-05-17 17:53:27 -0400234https://developers.google.com/protocol-buffers/