Protobuf and gRPC C ++ environment construction on Ubuntu 18.04

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).

environment

reference: Introduction to new technology "gRPC" for inter-service communication

install protobuf

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 gRPC

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

Run gRPC example

$ 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

Generate grpc and protobuf C ++ code from proto files

$ 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

Protobuf and gRPC C ++ environment construction on Ubuntu 18.04
Try running ScalarDB on WSL Ubuntu (Environment Construction)
Docker + DynamoDB local + C ++ environment construction and practice
[Flutter] Ubuntu 20.04 environment construction
Laravel environment construction (Ubuntu 18.04 LTS)
[Windows] WSL2 + Ubuntu + Node.js environment construction
Install JDK and JRE on Ubuntu 16.10
Ruby on Rails 6.0 environment construction memo
Build a XAMPP environment on Ubuntu
Rails on Docker environment construction procedure
Enable Java 8 and Java 11 SDKs on Ubuntu
Installing and using Ansible on Ubuntu 16.04
Create a development environment for Ruby 3.0.0 and Rails 6.1.0 on Ubuntu 20.04.1 LTS
Spring Boot environment construction memo on mac
Java development environment construction memo on Mac
Use docker in proxy environment on ubuntu 20.04.1
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
[Ruby] Building a Ruby development environment on Ubuntu
Muscle Ruby on Rails Day 1 ~ Environment Construction ~
Environment construction summary with rvm and postgresql
Minimal Java environment construction and Hello World
I wrote COBOL ~ Execute the program from the environment construction by Ubuntu and GnuCOBOL ~
Build and install Wireshark Development Release (3.3.1) on Ubuntu
Publish MySQL externally and log in on Ubuntu
Environment construction command memo with Docker on AWS
Kaggle environment construction using official Docker and vscode
[Ubuntu 18.04] Environment construction for using PyTorch with RTX3090
[Java] Build Java development environment on Ubuntu & check execution
Build a DHCP and NAT router on Ubuntu 16.04
[Notepad ++] C language / Java compilation & execution environment construction
[Personal memo] Ruby on Rails environment construction (Windows)
Install and switch between multiple Javas on Ubuntu
Docker on Ubuntu18.04 on WSL2 and VSCode installation instructions
A reminder of Docker and development environment construction
Ruby on Rails development environment construction on M1 Mac
How to build a Pytorch environment on Ubuntu
On ubuntu, scilab, octave and R, sympy, etc.
Install Ubuntu 20.04 in virtual box on windows10 and build a development environment using docker
[Java] Environment construction
Java environment construction
[Spring] Environment construction
Docker environment construction
tmux on Ubuntu
Build Ubuntu 20.04 LTS desktop environment on Raspberry Pi 4 (+ Japanese)
[Environment construction] Ruby on Rails 5.2 system development environment construction [within 1 hour]
Java development environment construction on Mac-JDK Install (2020 preservation version)
I built an Ubuntu environment on Windows 10 using WSL2.
Setting up the FreeBSD desktop environment on Ubuntu + qemu
Deploy to Ruby on Rails Elastic beanstalk (Environment construction)
I tried using YOLO v4 on Ubuntu and ROS
[Environment construction Mac] Ruby on Rails (+ Webpacker handles errors)
GOOS book Openfire On MacOS Mojave environment construction memo
Install rbenv with apt on ubuntu and put ruby
Ruby on Rails environment construction using VirtualBox, Vagrant, cyberduck
Prepare the environment for java11 and javaFx with Ubuntu 18.4
Install Rust in WSL2 Ubuntu environment and build WASM build environment
Talk about introducing Ubuntu 20.04 on Windows 10 and text editor
Java + Spring development environment construction with VirtualBox + Ubuntu (Xfce4)
Build TensorFlow 2.3.1 from source on Ubuntu20.04 LTS and create a shared library in C ++ language