Ubuntu14.04 安装gRPC编译helloword实例

一、安装gRPC

1.安装相关工具

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


点击yes即可。

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

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.

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

如果出现错误:

root@chenwr-VirtualBox:/home/workspace# cmake --version
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
/usr/local/bin
Segmentation fault (core dumped)

sudo apt-get remove cmake 卸载之前安装的旧版本cmake

gRPC编译成功。

二、编译helloworld

使用cmake进行编译或者直接使用make都可以。

进入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

也可以通过cmake的方式
cd third_party/protobuf
mdir cmake/build
cd cmake/build
cmake -Dprotobuf_BUILD_TESTS=OFF …
make -j8

cmake…会提示错误,使用cmake -Dprotobuf_BUILD_TESTS=OFF …进行配置即可。如果想编译成动态库,可添加-DBUILD_SHARED_LIBS=ON编译选项。


编译成功





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

或者在helloworld目录下创建build,不过个人觉得还是cmake的方式比较好用。进阶的话可以使用cmake-gui来进行更多配置。
cd build
cmake …
make -j8




发布了36 篇原创文章 · 获赞 6 · 访问量 1万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览