1. 安装3.13以上的cmake
apt remove cmake
wget https://cmake.org/files/v3.17/cmake-3.17.2.tar.gz
tar zxvf cmake-3.17.2.tar.gz
cd cmake-3.17.2
./configure
sudo make && make install
2. 安装openssl
apt remove openssl
wget https://www.openssl.org/source/openssl-1.1.1b.tar.gz
tar -xvf openssl-1.1.1b.tar.gz
cd openssl-1.1.1b
./config --prefix=/usr/local --openssldir=/usr/local/openssl
make && make install
vim ~/.bashrc
export PATH=/usr/local/openssl/bin:${PATH}
export OPENSSL_ROOT_DIR=/usr/local/openssl
export OPENSSL_LIBRARIES=/usr/local/openssl/lib
source ~/.bashrc
3. 安装grpc工具
sudo apt install -y build-essential autoconf libtool pkg-config
4. 下载grpc
git clone -b v1.28.0 https://github.com/grpc/grpc.git
cd grpc
git submodule update --init
5. 安装grpc的absl依赖
# Install openssl (to use instead of boringssl)
apt-get update && apt-get install -y libssl-dev
cd grpc/third_party/abseil-cpp/cmake/build
mkdir build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ..
make install
6. 安装grpc的c-ares依赖
# Install c-ares
# If the distribution provides a new-enough version of c-ares,
# this section can be replaced with:
# apt-get install -y libc-ares-dev
cd grpc/third_party/cares/cares
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make install
7. 安装grpc的benchmarks依赖
cd grpc/third_party/benchmarks
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make install
8. 安装grpc的protobuf依赖
cd grpc/third_party/protobuf/cmake
mkdir build
cd build
cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release ..
make install
9. 安装grpc的zlib依赖
cd grpc/third_party/zlib
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make install
10.安装grpc
cd grpc
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release \
-DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DgRPC_CARES_PROVIDER=package \
-DgRPC_ABSL_PROVIDER=package \
-DgRPC_PROTOBUF_PROVIDER=package \
-DgRPC_SSL_PROVIDER=package \
-DgRPC_ZLIB_PROVIDER=package ..
make install
11.构建hello world
cd grpc/examples/cpp/helloworld
mkdir build
cd build
cmake ..
make