Linux HOWTOs

About | Home | Search


ERROR: Slooooow dooooown... this page load was delayed.

HOWTO: protobuf
Description: Google Protocol Buffers
Click here for ChangeLog
NOTE: I use GNU tar >= 1.13.25 so it's -j for .tar.bz2 files,
it's safe to assume that make, gcc, binutils, fileutils/coreutils, gawk, sed, and grep are prerequisites for almost everything


# Google Protocol Buffers
# =======================
# Include examples of installing it from a release tarball, and from the
# Git repository

# This covers C++ only.  There are also Java, Python, Objective-C, C#,
# JavaScript, Ruby, Go, PHP, and Dart runtimes.

# To remove protobuf or clean up files from an old version before installing
# a new one, skip down to the bottom for instructions

# I include 3.6.0 below, the latest as I type this, and 3.5.1 because that
# is the latest version that would allow me to build protobuf-c


# From a release tarball
# ======================
# Prerequisites:
# pkg-config
# zlib >= 1.2.0.4
# GCC with C++11 support (>= 4.8.1)
# Python

# Get it
cd
test -f installed/protobuf-cpp-3.6.0.tar.gz &&
 mv -f installed/protobuf-cpp-3.6.0.tar.gz .
test ! -f protobuf-cpp-3.6.0.tar.gz &&
 wget --no-check-certificate https://github.com/google/protobuf/releases/\
download/v3.6.0/protobuf-cpp-3.6.0.tar.gz

# Extract the source
mkdir -p -m 0700 src
cd src
test -d ./protobuf && rm -r ./protobuf
find -maxdepth 1 -type d -name "protobuf-*" -exec rm -r {} \;
tar xzvf ~/protobuf-cpp-3.6.0.tar.gz
cd protobuf-3.6.0
test $UID = 0 && chown -R root:root .

# Read ./README.md

# Configure the build for 64-bit
test $(uname -m) = 'x86_64' &&
./configure --libdir=/usr/local/lib64 --with-gnu-ld --disable-static

# Configure the build for anything else
test $(uname -m) != 'x86_64' &&
./configure --with-gnu-ld --disable-static

# Build it
make

# Check the build
make check

# Become root to install it
su

# Install it
make install
ldconfig

# Become your non-root user again
exit

# Save the source for later
cd
mkdir -p -m 0700 installed
rm -f installed/protobuf-cpp-*.tar.*
mv protobuf-cpp-3.6.0.tar.gz installed/


# From a release tarball
# ======================
# Prerequisites:
# pkg-config
# zlib >= 1.2.0.4
# GCC with C++11 support (>= 4.8.1)
# Python

# Get it
cd
test -f installed/protobuf-cpp-3.5.1.tar.gz &&
 mv -f installed/protobuf-cpp-3.5.1.tar.gz .
test ! -f protobuf-cpp-3.5.1.tar.gz &&
 wget --no-check-certificate https://github.com/google/protobuf/releases/\
download/v3.5.1/protobuf-cpp-3.5.1.tar.gz

# Extract the source
mkdir -p -m 0700 src
cd src
test -d ./protobuf && rm -r ./protobuf
find -maxdepth 1 -type d -name "protobuf-*" -exec rm -r {} \;
tar xzvf ~/protobuf-cpp-3.5.1.tar.gz
cd protobuf-3.5.1
test $UID = 0 && chown -R root:root .

# Read ./README.md

# Configure the build for 64-bit
test $(uname -m) = 'x86_64' &&
./configure --libdir=/usr/local/lib64 --with-gnu-ld --disable-static

# Configure the build for anything else
test $(uname -m) != 'x86_64' &&
./configure --with-gnu-ld --disable-static

# Build it
make

# Check the build
make check

# Become root to install it
su

# Install it
make install
ldconfig

# Become your non-root user again
exit

# Save the source for later
cd
mkdir -p -m 0700 installed
rm -f installed/protobuf-cpp-*.tar.*
mv protobuf-cpp-3.5.1.tar.gz installed/


# From the Git repository
# =======================
# Prerequisites:
# Git
# autoconf
# automake
# libtool
# pkg-config
# zlib >= 1.2.0.4
# GCC with C++11 support (>= 4.8.1)

# Get it - clone the repository
cd
mkdir -p -m 0700 src
cd src
find -maxdepth 1 -type d -name "protobuf-*" -exec rm -r {} \;
test ! -d protobuf && git clone https://github.com/google/protobuf.git
cd protobuf
git submodule update --init --recursive

# If you're re-using a clone from before
git fetch

# Generate ./configure, etc.
./autogen.sh

# Configure it
./configure --with-gnu-ld

# Build it
make

# Check the build
make check

# Become root to install it
su

# Install it
make install
ldconfig

# Become your non-root user again
exit

## Done



# If you ever want to uninstall protobuf, this should do it:
# ('make uninstall' as root should do it, the rest is just in case)
cd
su
test -d src/protobuf-* && ( cd src/protobuf-* ; make uninstall )
test -d src/protobuf &&
 ( cd src/protobuf ; make uninstall ; cd .. ; rm -r ./protobuf/ )
rm -f /usr/local/bin/protoc
test -d /usr/local/include/google/protobuf &&
 rm -r /usr/local/include/google/protobuf
rmdir --ignore-fail-on-non-empty /usr/local/include/google
for libdir in /usr/local/lib /usr/local/lib64;
do
  test -d $libdir &&
   ( cd $libdir
     rm -f libprotobuf-lite.* libprotobuf.* libprotoc.*
     test -d pkgconfig &&
      ( cd pkgconfig ; rm -f protobuf.pc protobuf-lite.pc ) )
done
ldconfig
exit
find ~/src -maxdepth 1 -type d -name "protobuf-*" -exec rm -r {} \;
rm -f ~/installed/protobuf-*.tar.*

Back to the list


Last updated: Tue, 07 Aug 2018 12:06:17 -0400
Jason Englander <jason at englanders dot us>