1*6777b538SAndroid Build Coastguard WorkerProtocol Buffers - Google's data interchange format 2*6777b538SAndroid Build Coastguard Worker=================================================== 3*6777b538SAndroid Build Coastguard Worker 4*6777b538SAndroid Build Coastguard WorkerCopyright 2008 Google Inc. 5*6777b538SAndroid Build Coastguard Worker 6*6777b538SAndroid Build Coastguard Workerhttps://developers.google.com/protocol-buffers/ 7*6777b538SAndroid Build Coastguard Worker 8*6777b538SAndroid Build Coastguard WorkerC++ Installation - Unix 9*6777b538SAndroid Build Coastguard Worker----------------------- 10*6777b538SAndroid Build Coastguard Worker 11*6777b538SAndroid Build Coastguard WorkerTo build protobuf from source, the following tools are needed: 12*6777b538SAndroid Build Coastguard Worker 13*6777b538SAndroid Build Coastguard Worker * autoconf 14*6777b538SAndroid Build Coastguard Worker * automake 15*6777b538SAndroid Build Coastguard Worker * libtool 16*6777b538SAndroid Build Coastguard Worker * make 17*6777b538SAndroid Build Coastguard Worker * g++ 18*6777b538SAndroid Build Coastguard Worker * unzip 19*6777b538SAndroid Build Coastguard Worker 20*6777b538SAndroid Build Coastguard WorkerOn Ubuntu/Debian, you can install them with: 21*6777b538SAndroid Build Coastguard Worker 22*6777b538SAndroid Build Coastguard Worker sudo apt-get install autoconf automake libtool curl make g++ unzip 23*6777b538SAndroid Build Coastguard Worker 24*6777b538SAndroid Build Coastguard WorkerOn other platforms, please use the corresponding package managing tool to 25*6777b538SAndroid Build Coastguard Workerinstall them before proceeding. 26*6777b538SAndroid Build Coastguard Worker 27*6777b538SAndroid Build Coastguard WorkerTo get the source, download one of the release .tar.gz or .zip packages in the 28*6777b538SAndroid Build Coastguard Workerrelease page: 29*6777b538SAndroid Build Coastguard Worker 30*6777b538SAndroid Build Coastguard Worker https://github.com/protocolbuffers/protobuf/releases/latest 31*6777b538SAndroid Build Coastguard Worker 32*6777b538SAndroid Build Coastguard WorkerFor example: if you only need C++, download `protobuf-cpp-[VERSION].tar.gz`; if 33*6777b538SAndroid Build Coastguard Workeryou need C++ and Java, download `protobuf-java-[VERSION].tar.gz` (every package 34*6777b538SAndroid Build Coastguard Workercontains C++ source already); if you need C++ and multiple other languages, 35*6777b538SAndroid Build Coastguard Workerdownload `protobuf-all-[VERSION].tar.gz`. 36*6777b538SAndroid Build Coastguard Worker 37*6777b538SAndroid Build Coastguard WorkerYou can also get the source by "git clone" our git repository. Make sure you 38*6777b538SAndroid Build Coastguard Workerhave also cloned the submodules and generated the configure script (skip this 39*6777b538SAndroid Build Coastguard Workerif you are using a release .tar.gz or .zip package): 40*6777b538SAndroid Build Coastguard Worker 41*6777b538SAndroid Build Coastguard Worker git clone https://github.com/protocolbuffers/protobuf.git 42*6777b538SAndroid Build Coastguard Worker cd protobuf 43*6777b538SAndroid Build Coastguard Worker git submodule update --init --recursive 44*6777b538SAndroid Build Coastguard Worker ./autogen.sh 45*6777b538SAndroid Build Coastguard Worker 46*6777b538SAndroid Build Coastguard WorkerTo build and install the C++ Protocol Buffer runtime and the Protocol 47*6777b538SAndroid Build Coastguard WorkerBuffer compiler (protoc) execute the following: 48*6777b538SAndroid Build Coastguard Worker 49*6777b538SAndroid Build Coastguard Worker 50*6777b538SAndroid Build Coastguard Worker ./configure 51*6777b538SAndroid Build Coastguard Worker make -j$(nproc) # $(nproc) ensures it uses all cores for compilation 52*6777b538SAndroid Build Coastguard Worker make check 53*6777b538SAndroid Build Coastguard Worker sudo make install 54*6777b538SAndroid Build Coastguard Worker sudo ldconfig # refresh shared library cache. 55*6777b538SAndroid Build Coastguard Worker 56*6777b538SAndroid Build Coastguard WorkerIf "make check" fails, you can still install, but it is likely that 57*6777b538SAndroid Build Coastguard Workersome features of this library will not work correctly on your system. 58*6777b538SAndroid Build Coastguard WorkerProceed at your own risk. 59*6777b538SAndroid Build Coastguard Worker 60*6777b538SAndroid Build Coastguard WorkerFor advanced usage information on configure and make, please refer to the 61*6777b538SAndroid Build Coastguard Workerautoconf documentation: 62*6777b538SAndroid Build Coastguard Worker 63*6777b538SAndroid Build Coastguard Worker http://www.gnu.org/software/autoconf/manual/autoconf.html#Running-configure-Scripts 64*6777b538SAndroid Build Coastguard Worker 65*6777b538SAndroid Build Coastguard Worker**Hint on install location** 66*6777b538SAndroid Build Coastguard Worker 67*6777b538SAndroid Build Coastguard WorkerBy default, the package will be installed to /usr/local. However, 68*6777b538SAndroid Build Coastguard Workeron many platforms, /usr/local/lib is not part of LD_LIBRARY_PATH. 69*6777b538SAndroid Build Coastguard WorkerYou can add it, but it may be easier to just install to /usr 70*6777b538SAndroid Build Coastguard Workerinstead. To do this, invoke configure as follows: 71*6777b538SAndroid Build Coastguard Worker 72*6777b538SAndroid Build Coastguard Worker ./configure --prefix=/usr 73*6777b538SAndroid Build Coastguard Worker 74*6777b538SAndroid Build Coastguard WorkerIf you already built the package with a different prefix, make sure 75*6777b538SAndroid Build Coastguard Workerto run "make clean" before building again. 76*6777b538SAndroid Build Coastguard Worker 77*6777b538SAndroid Build Coastguard Worker**Compiling dependent packages** 78*6777b538SAndroid Build Coastguard Worker 79*6777b538SAndroid Build Coastguard WorkerTo compile a package that uses Protocol Buffers, you need to pass 80*6777b538SAndroid Build Coastguard Workervarious flags to your compiler and linker. As of version 2.2.0, 81*6777b538SAndroid Build Coastguard WorkerProtocol Buffers integrates with pkg-config to manage this. If you 82*6777b538SAndroid Build Coastguard Workerhave pkg-config installed, then you can invoke it to get a list of 83*6777b538SAndroid Build Coastguard Workerflags like so: 84*6777b538SAndroid Build Coastguard Worker 85*6777b538SAndroid Build Coastguard Worker 86*6777b538SAndroid Build Coastguard Worker pkg-config --cflags protobuf # print compiler flags 87*6777b538SAndroid Build Coastguard Worker pkg-config --libs protobuf # print linker flags 88*6777b538SAndroid Build Coastguard Worker pkg-config --cflags --libs protobuf # print both 89*6777b538SAndroid Build Coastguard Worker 90*6777b538SAndroid Build Coastguard Worker 91*6777b538SAndroid Build Coastguard WorkerFor example: 92*6777b538SAndroid Build Coastguard Worker 93*6777b538SAndroid Build Coastguard Worker c++ my_program.cc my_proto.pb.cc `pkg-config --cflags --libs protobuf` 94*6777b538SAndroid Build Coastguard Worker 95*6777b538SAndroid Build Coastguard WorkerNote that packages written prior to the 2.2.0 release of Protocol 96*6777b538SAndroid Build Coastguard WorkerBuffers may not yet integrate with pkg-config to get flags, and may 97*6777b538SAndroid Build Coastguard Workernot pass the correct set of flags to correctly link against 98*6777b538SAndroid Build Coastguard Workerlibprotobuf. If the package in question uses autoconf, you can 99*6777b538SAndroid Build Coastguard Workeroften fix the problem by invoking its configure script like: 100*6777b538SAndroid Build Coastguard Worker 101*6777b538SAndroid Build Coastguard Worker 102*6777b538SAndroid Build Coastguard Worker configure CXXFLAGS="$(pkg-config --cflags protobuf)" \ 103*6777b538SAndroid Build Coastguard Worker LIBS="$(pkg-config --libs protobuf)" 104*6777b538SAndroid Build Coastguard Worker 105*6777b538SAndroid Build Coastguard WorkerThis will force it to use the correct flags. 106*6777b538SAndroid Build Coastguard Worker 107*6777b538SAndroid Build Coastguard WorkerIf you are writing an autoconf-based package that uses Protocol 108*6777b538SAndroid Build Coastguard WorkerBuffers, you should probably use the PKG_CHECK_MODULES macro in your 109*6777b538SAndroid Build Coastguard Workerconfigure script like: 110*6777b538SAndroid Build Coastguard Worker 111*6777b538SAndroid Build Coastguard Worker PKG_CHECK_MODULES([protobuf], [protobuf]) 112*6777b538SAndroid Build Coastguard Worker 113*6777b538SAndroid Build Coastguard WorkerSee the pkg-config man page for more info. 114*6777b538SAndroid Build Coastguard Worker 115*6777b538SAndroid Build Coastguard WorkerIf you only want protobuf-lite, substitute "protobuf-lite" in place 116*6777b538SAndroid Build Coastguard Workerof "protobuf" in these examples. 117*6777b538SAndroid Build Coastguard Worker 118*6777b538SAndroid Build Coastguard Worker**Note for Mac users** 119*6777b538SAndroid Build Coastguard Worker 120*6777b538SAndroid Build Coastguard WorkerFor a Mac system, Unix tools are not available by default. You will first need 121*6777b538SAndroid Build Coastguard Workerto install Xcode from the Mac AppStore and then run the following command from 122*6777b538SAndroid Build Coastguard Workera terminal: 123*6777b538SAndroid Build Coastguard Worker 124*6777b538SAndroid Build Coastguard Worker sudo xcode-select --install 125*6777b538SAndroid Build Coastguard Worker 126*6777b538SAndroid Build Coastguard WorkerTo install Unix tools, you can install "port" following the instructions at 127*6777b538SAndroid Build Coastguard Workerhttps://www.macports.org . This will reside in /opt/local/bin/port for most 128*6777b538SAndroid Build Coastguard WorkerMac installations. 129*6777b538SAndroid Build Coastguard Worker 130*6777b538SAndroid Build Coastguard Worker sudo /opt/local/bin/port install autoconf automake libtool 131*6777b538SAndroid Build Coastguard Worker 132*6777b538SAndroid Build Coastguard WorkerAlternative for Homebrew users: 133*6777b538SAndroid Build Coastguard Worker 134*6777b538SAndroid Build Coastguard Worker brew install autoconf automake libtool 135*6777b538SAndroid Build Coastguard Worker 136*6777b538SAndroid Build Coastguard WorkerThen follow the Unix instructions above. 137*6777b538SAndroid Build Coastguard Worker 138*6777b538SAndroid Build Coastguard Worker**Note for cross-compiling** 139*6777b538SAndroid Build Coastguard Worker 140*6777b538SAndroid Build Coastguard WorkerThe makefiles normally invoke the protoc executable that they just 141*6777b538SAndroid Build Coastguard Workerbuilt in order to build tests. When cross-compiling, the protoc 142*6777b538SAndroid Build Coastguard Workerexecutable may not be executable on the host machine. In this case, 143*6777b538SAndroid Build Coastguard Workeryou must build a copy of protoc for the host machine first, then use 144*6777b538SAndroid Build Coastguard Workerthe --with-protoc option to tell configure to use it instead. For 145*6777b538SAndroid Build Coastguard Workerexample: 146*6777b538SAndroid Build Coastguard Worker 147*6777b538SAndroid Build Coastguard Worker ./configure --with-protoc=protoc 148*6777b538SAndroid Build Coastguard Worker 149*6777b538SAndroid Build Coastguard WorkerThis will use the installed protoc (found in your $PATH) instead of 150*6777b538SAndroid Build Coastguard Workertrying to execute the one built during the build process. You can 151*6777b538SAndroid Build Coastguard Workeralso use an executable that hasn't been installed. For example, if 152*6777b538SAndroid Build Coastguard Workeryou built the protobuf package for your host machine in ../host, 153*6777b538SAndroid Build Coastguard Workeryou might do: 154*6777b538SAndroid Build Coastguard Worker 155*6777b538SAndroid Build Coastguard Worker ./configure --with-protoc=../host/src/protoc 156*6777b538SAndroid Build Coastguard Worker 157*6777b538SAndroid Build Coastguard WorkerEither way, you must make sure that the protoc executable you use 158*6777b538SAndroid Build Coastguard Workerhas the same version as the protobuf source code you are trying to 159*6777b538SAndroid Build Coastguard Workeruse it with. 160*6777b538SAndroid Build Coastguard Worker 161*6777b538SAndroid Build Coastguard Worker**Note for Solaris users** 162*6777b538SAndroid Build Coastguard Worker 163*6777b538SAndroid Build Coastguard WorkerSolaris 10 x86 has a bug that will make linking fail, complaining 164*6777b538SAndroid Build Coastguard Workerabout libstdc++.la being invalid. We have included a work-around 165*6777b538SAndroid Build Coastguard Workerin this package. To use the work-around, run configure as follows: 166*6777b538SAndroid Build Coastguard Worker 167*6777b538SAndroid Build Coastguard Worker ./configure LDFLAGS=-L$PWD/src/solaris 168*6777b538SAndroid Build Coastguard Worker 169*6777b538SAndroid Build Coastguard WorkerSee src/solaris/libstdc++.la for more info on this bug. 170*6777b538SAndroid Build Coastguard Worker 171*6777b538SAndroid Build Coastguard Worker**Note for HP C++ Tru64 users** 172*6777b538SAndroid Build Coastguard Worker 173*6777b538SAndroid Build Coastguard WorkerTo compile invoke configure as follows: 174*6777b538SAndroid Build Coastguard Worker 175*6777b538SAndroid Build Coastguard Worker ./configure CXXFLAGS="-O -std ansi -ieee -D__USE_STD_IOSTREAM" 176*6777b538SAndroid Build Coastguard Worker 177*6777b538SAndroid Build Coastguard WorkerAlso, you will need to use gmake instead of make. 178*6777b538SAndroid Build Coastguard Worker 179*6777b538SAndroid Build Coastguard Worker**Note for AIX users** 180*6777b538SAndroid Build Coastguard Worker 181*6777b538SAndroid Build Coastguard WorkerCompile using the IBM xlC C++ compiler as follows: 182*6777b538SAndroid Build Coastguard Worker 183*6777b538SAndroid Build Coastguard Worker ./configure CXX=xlC 184*6777b538SAndroid Build Coastguard Worker 185*6777b538SAndroid Build Coastguard WorkerAlso, you will need to use GNU `make` (`gmake`) instead of AIX `make`. 186*6777b538SAndroid Build Coastguard Worker 187*6777b538SAndroid Build Coastguard WorkerC++ Installation - Windows 188*6777b538SAndroid Build Coastguard Worker-------------------------- 189*6777b538SAndroid Build Coastguard Worker 190*6777b538SAndroid Build Coastguard WorkerIf you only need the protoc binary, you can download it from the release 191*6777b538SAndroid Build Coastguard Workerpage: 192*6777b538SAndroid Build Coastguard Worker 193*6777b538SAndroid Build Coastguard Worker https://github.com/protocolbuffers/protobuf/releases/latest 194*6777b538SAndroid Build Coastguard Worker 195*6777b538SAndroid Build Coastguard WorkerIn the downloads section, download the zip file protoc-$VERSION-win32.zip. 196*6777b538SAndroid Build Coastguard WorkerIt contains the protoc binary as well as public proto files of protobuf 197*6777b538SAndroid Build Coastguard Workerlibrary. 198*6777b538SAndroid Build Coastguard Worker 199*6777b538SAndroid Build Coastguard WorkerProtobuf and its dependencies can be installed directly by using `vcpkg`: 200*6777b538SAndroid Build Coastguard Worker 201*6777b538SAndroid Build Coastguard Worker >vcpkg install protobuf protobuf:x64-windows 202*6777b538SAndroid Build Coastguard Worker 203*6777b538SAndroid Build Coastguard WorkerIf zlib support is desired, you'll also need to install the zlib feature: 204*6777b538SAndroid Build Coastguard Worker 205*6777b538SAndroid Build Coastguard Worker >vcpkg install protobuf[zlib] protobuf[zlib]:x64-windows 206*6777b538SAndroid Build Coastguard Worker 207*6777b538SAndroid Build Coastguard WorkerSee https://github.com/Microsoft/vcpkg for more information. 208*6777b538SAndroid Build Coastguard Worker 209*6777b538SAndroid Build Coastguard WorkerTo build from source using Microsoft Visual C++, see [cmake/README.md](../cmake/README.md). 210*6777b538SAndroid Build Coastguard Worker 211*6777b538SAndroid Build Coastguard WorkerTo build from source using Cygwin or MinGW, follow the Unix installation 212*6777b538SAndroid Build Coastguard Workerinstructions, above. 213*6777b538SAndroid Build Coastguard Worker 214*6777b538SAndroid Build Coastguard WorkerBinary Compatibility Warning 215*6777b538SAndroid Build Coastguard Worker---------------------------- 216*6777b538SAndroid Build Coastguard Worker 217*6777b538SAndroid Build Coastguard WorkerDue to the nature of C++, it is unlikely that any two versions of the 218*6777b538SAndroid Build Coastguard WorkerProtocol Buffers C++ runtime libraries will have compatible ABIs. 219*6777b538SAndroid Build Coastguard WorkerThat is, if you linked an executable against an older version of 220*6777b538SAndroid Build Coastguard Workerlibprotobuf, it is unlikely to work with a newer version without 221*6777b538SAndroid Build Coastguard Workerre-compiling. This problem, when it occurs, will normally be detected 222*6777b538SAndroid Build Coastguard Workerimmediately on startup of your app. Still, you may want to consider 223*6777b538SAndroid Build Coastguard Workerusing static linkage. You can configure this package to install 224*6777b538SAndroid Build Coastguard Workerstatic libraries only using: 225*6777b538SAndroid Build Coastguard Worker 226*6777b538SAndroid Build Coastguard Worker ./configure --disable-shared 227*6777b538SAndroid Build Coastguard Worker 228*6777b538SAndroid Build Coastguard WorkerUsage 229*6777b538SAndroid Build Coastguard Worker----- 230*6777b538SAndroid Build Coastguard Worker 231*6777b538SAndroid Build Coastguard WorkerThe complete documentation for Protocol Buffers is available via the 232*6777b538SAndroid Build Coastguard Workerweb at: 233*6777b538SAndroid Build Coastguard Worker 234*6777b538SAndroid Build Coastguard Workerhttps://developers.google.com/protocol-buffers/ 235