Compile gRPC C++ on CentOS 7.4
Step 1. Install cmake 3.23.1
wget https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1.tar.gz
tar -xzvf cmake-3.23.1.tar.gz
cd cmake-3.23.1
./bootstrap
make
sudo make install
Step 2. Install gcc/g++ 8
sudo yum install centos-release-scl
sudo yum install devtoolset-8-gcc*
scl enable devtoolset-8 bash
gcc -v
Step 3. Install other tools
sudo yum install -y build-essential autoconf libtool pkg-config
Step 4. Setup system environment variables
export MY_INSTALL_DIR=$HOME/.local
mkdir -p $MY_INSTALL_DIR
export PATH="$MY_INSTALL_DIR/bin:$PATH"
Step 5. Download gRPC C++ source code
git clone -b v1.45.0 https://github.com/grpc/grpc
cd grpc
git submodule update --init
Step 6. Compile gRPC C++
cd grpc
mkdir -p cmake/build
pushd cmake/build
cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR ../..
make
make install
popd
Step 7. Build example helloworld
cd grpc/examples/cpp/helloworld
mkdir -p cmake/build
pushd cmake/build
cmake -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR ../..
make
Step 8. Run example helloworld
(1) Run the server:
./greeter_server
(2) From a different terminal, run the client and see the client output:
./greeter_client
Greeter received: Hello world
Reference:
https://grpc.io/docs/languages/cpp/quickstart/#build-and-install-grpc-and-protocol-buffers