Build an environment for Protobuf (3.6.1) and gRPC (v1.18.0) on Ubuntu 18.04.
There is a version dependency between Protobuf and gRPC.
In the development environment, the latest Protobuf (3.13.0) cannot be used, so use the supported Protobuf (3.6.1). Also, since the latest gRPC (1.32.0) cannot be compiled with the old Protobuf (3.6.1), I will use gRPC (v1.18.0) with Protobuf (3.6.1).
reference: Introduction to new technology "gRPC" for inter-service communication
You can also install protobuf from the protobuf repository and gRPC's third_party / protobuf folder.
--Uninstall apt protobuf 3.0.0
If you have already installed it with apt-get, uninstall it. (Apt-get protobuf is 3.0.0)
sudo apt-get remove protobuf-compiler
sudo apt-get remove libprotobuf-dev
sudo apt-get remove libprotobuf-lite10
--Installing protobuf 3.6.1.
sudo apt-get install autoconf automake libtool curl make g++ unzip
git clone -b 3.6.x https://github.com/protocolbuffers/protobuf.git
cd protobuf
git submodule update --init --recursive
./autogen.sh
./configure
make
make check
sudo make install
sudo ldconfig # refresh shared library cache.
--Check the version of protobuf
$ protoc --version
libprotoc 3.6.1
$ which protoc
/usr/local/bin/protoc
Install it in $ HOME / .local.
--Setting of MY_INSTALL_DIR
$ export MY_INSTALL_DIR=$HOME/.local
$ mkdir -p $MY_INSTALL_DIR
$ export PATH="$PATH:$MY_INSTALL_DIR/bin"
Add PATH to ~ / .bashrc
export PATH=$PATH:$HOME/.local/bin
--installing cmake
$ sudo apt-get install cmake
$ cmake --version
cmake version 3.10.2
You need cmake version 3.13 or later, so install a new cmake.
$ wget -q -O cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v3.17.0/cmake-3.17.0-Linux-x86_64.sh
$ sh cmake-linux.sh -- --skip-license --prefix=$MY_INSTALL_DIR
$ rm cmake-linux.sh
--Installing Pre-requisites
$ sudo apt-get install build-essential autoconf libtool pkg-config libssl-dev
--Get repository
$ git clone --recurse-submodules -b v1.18.0 https://github.com/grpc/grpc
$ cd grpc
cd third_party/cares/cares
git fetch origin
git checkout cares-1_13_0
mkdir -p cmake/build
cd cmake/build
cmake -DCMAKE_BUILD_TYPE=Release ../..
sudo make -j4 install
rm -rf third_party/cares/cares # wipe out to prevent influencing the grpc build
cd third_party/zlib
mkdir -p cmake/build
cd cmake/build
cmake -DCMAKE_BUILD_TYPE=Release ../..
sudo make -j4 install
rm -rf third_party/zlib # wipe out to prevent influencing the grpc build
Not required if you have already installed from the protobuf repository. You can safely install it again from third_party / protobuf.
cd third_party/protobuf
mkdir -p cmake/build
cd cmake/build
cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release ..
sudo make -j4 install
rm -rf third_party/protobuf # wipe out to prevent influencing the grpc build
cd grpc
mkdir -p cmake/build
cd cmake/build
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DgRPC_CARES_PROVIDER=package \
-DgRPC_PROTOBUF_PROVIDER=package \
-DgRPC_SSL_PROVIDER=package \
-DgRPC_ZLIB_PROVIDER=package \
-DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR \
../..
make -j4 install
$ protoc --version
libprotoc 3.6.1
$ which protoc
/usr/local/bin/protoc
$ cd examples/cpp/helloworld
$ mkdir -p cmake/build
$ cd cmake/build
$ cmake ../..
$ make -j
$ ./greeter_server
# From a different terminal
$ ./greeter_client
Greeter received: Hello world
$ protoc \
--grpc_out=./codegen \
--cpp_out=./codegen \
--plugin=protoc-gen-grpc=`which grpc_cpp_plugin` \
./telemetry.proto
$ cd codegen
$ ls
telemetry.grpc.pb.cc telemetry.grpc.pb.h telemetry.pb.cc telemetry.pb.h
Recommended Posts