安裝
全部採用源碼方式安裝
- 安裝cmake ,一般centos系統默認未2.8.12.2 但是實際運行程序最小要求3.5.1
[root@VM_117_243_centos ~/grpc/examples/cpp/helloworld]# cmake .
CMake Error at CMakeLists.txt:20 (cmake_minimum_required):
CMake 3.5.1 or higher is required. You are running version 2.8.12.2
這裏我們可以安裝3.13,以及更高的版本。當然也可以不這麼做,但是你會遇到很多麻煩事,具體詳情可以看這個issue(https://github.com/grpc/grpc/issues/22231)。其中這段話非常重要:
You need cmake 3.13 or newer to install everything that gRPC needs from gRPC installation.
Otherwise, you need to install all dependencies by yourselves. You can use this script as a reference.
cmake的安裝方法如下,採用源碼方式安裝:
- 首先卸載原有cmake (yum remove cmake)
[root@VM_117_243_centos ~/grpc/examples/cpp/helloworld]# yum remove cmake
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Resolving Dependencies
--> Running transaction check
---> Package cmake.x86_64 0:2.8.12.2-2.tl2 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================================================================================
Removing:
cmake x86_64 2.8.12.2-2.tl2 @tlinux 27 M
Transaction Summary
===========================================================================================================================================================================================
Remove 1 Package
Installed size: 27 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : cmake-2.8.12.2-2.tl2.x86_64 1/1
Verifying : cmake-2.8.12.2-2.tl2.x86_64 1/1
Removed:
cmake.x86_64 0:2.8.12.2-2.tl2
Complete!
[root@VM_117_243_centos ~/grpc/examples/cpp/helloworld]# cmake --version
-bash: /usr/bin/cmake: No such file or directory
[root@VM_117_243_centos ~/grpc/examples/cpp/helloworld]#
- wget https://github.com/Kitware/CMake/releases/download/v3.17.2/cmake-3.17.2.tar.gz
- tar -xvzf cmake-3.17.2.tar.gz
- ./bootstrap
- gmake -j4 (-j4採用多線程編譯,加快速度)
- gmake install
- source /etc/profile (這一步如果不做,cmake --verison會找不到cmake)
- 安裝protobuf
- git clone https://github.com/protocolbuffers/protobuf.git
- git submodule update --init --recursive.
- ./autogen.sh
- ./configure
- make -j4
- make check
- make install
- 安裝grpc
- git clone https://github.com/grpc/grpc.git --recurse-submodules
- cd grpc
- make
- make install #安裝完成
- cd example/cpp/helloworld
- cmake .
之後編譯,出現這個錯誤:
CMake Error at CMakeLists.txt:103 (find_package):
Could not find a package configuration file provided by "Protobuf" with any
of the following names:
ProtobufConfig.cmake
protobuf-config.cmake
解決方法:
參考:https://groups.google.com/forum/#!topic/protobuf/BoWqjv1e84s
1.enter the "protobuf/cmake/" dir.
2.mkdir build. protobuf/cmake/build
3.cmake ..
4.make && make install
但是有出現了另外一個問題,grpc又報這個錯誤了。。。。。:
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.7")
-- Using protobuf
CMake Error at CMakeLists.txt:116 (find_package):
Could not find a package configuration file provided by "gRPC" with any of
the following names:
gRPCConfig.cmake
grpc-config.cmake
Add the installation prefix of "gRPC" to CMAKE_PREFIX_PATH or set
"gRPC_DIR" to a directory containing one of the above files. If "gRPC"
provides a separate development package or SDK, be sure it has been
installed.
同樣的解決方法:
在grpc/cmake/build目錄下
cmake ../../
make -j4
make install
- 運行第一個程序helloworld
- cd grpc/example/cpp/helloword
- mkdir -p cmake/build
- cd cmake/build
- cmake …/…
- make -j4
[root@VM_117_243_centos ~/grpc/examples/cpp/helloworld/cmake/build]# ./greeter_server
Server listening on 0.0.0.0:50051
[root@VM_117_243_centos ~/grpc/examples/cpp/helloworld/cmake/build]# ./greeter_client
Greeter received: Hello world
[root@VM_117_243_centos ~/grpc/examples/cpp/helloworld/cmake/build]#