Ubuntu14.04 安装gRPC编译helloword实例

一、安装gRPC

1.安装相关工具

sudo apt-get install build-essential autoconf libtool pkg-config
sudo apt-get install cmake
sudo apt-get install libgflags-dev clang-5.0 libc++-dev
image
image

点击yes即可。

Ubuntu14.04 安装clang-5.0时出错,因暂时不需要,跳过该工具安装即可。


image

2.编译命令

cd /home/workspace/project/grpc
mkdir -p cmake/build
cd cmake/build
cmake ../..
make -j8

虚拟机执行显示cmake提示版本过低。因Ubuntu14.04软件源的问题,sudo apt-get install cmake,默认安装2.8.12.2 。因此采用离线包的方式安装新版本cmake.


image

更新cmake版本

1.解压并安装所需的库
tar zxvf cmake-3.6.3.tar.gz
sudo apt-get install build-essential
sudo apt-get install pkg-config git
sudo apt-get install libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libtiff4.dev libswscale-dev libjasper-dev libdc1394-22-dev libgstreamer1.0-dev  libgstreamer-plugins-base1.0-dev

2.进入目录,执行./bootstrap
出现错误:

root@chenwr-pc:/home/workspace/test/face/cmake-3.6.3# ./bootstrap
---------------------------------------------
CMake 3.6.3, Copyright 2000-2016 Kitware, Inc.
C compiler on this system is: cc
---------------------------------------------
Error when bootstrapping CMake:
Cannot find appropriate C++ compiler on this system.
Please specify one using environment variable CXX.
See cmake_bootstrap.log for compilers attempted.
---------------------------------------------
Log of errors: /home/workspace/test/face/cmake-3.6.3/Bootstrap.cmk/cmake_bootstrap.log

解决办法:
sudo apt-get install g++

3.make -j 8
4.make install
5.cmake --version查看是否安装成功

root@chenwr-pc:/home/workspace/test/face/cmake-3.6.3# cmake --version
cmake version 3.6.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).

gRPC编译成功。


image

二、编译helloworld

进入example中helloworld的目录,执行make。出现错误,protoc: Command not found。

root@chenwr-pc:/home/workspace/project/grpc/examples/cpp/helloworld# make
 DEPENDENCY ERROR

You don't have protoc 3.0.0 installed in your path.
Please install Google protocol buffers 3.0.0 and its compiler.
You can find it here:

   https://github.com/google/protobuf/releases/tag/v3.0.0

Here is what I get when trying to evaluate your version of protoc:

protoc --version
make: protoc: Command not found
make: [system-check] Error 127 (ignored)


make: *** [system-check] Error 1

进入/usr/local/bin与/usr/local/lib 均没发现protoc与libprotobuf。原来/grpc/third_party/protobuf没有编译。

执行如下命令安装

cd third_party/protobuf
sudo ./autogen.sh
sudo ./configure
make -j8
sudo make install
image

image

安装完该库之后继续编译helloworld,编译成功,实际运行效果如下。


image

image

image

你可能感兴趣的:(Ubuntu14.04 安装gRPC编译helloword实例)