1. 一些工具安装

$ apt-get install build-essential autoconf libtool pkg-config

$ apt-get install libgflags-dev libgtest-dev

$ apt-get install clang libc++-dev

2. 源码下载

$ git clone -b v1.15.0 https://github.com/grpc/grpc

$ cd grpc

$ git submodule update --init

3. 编译

编译的话,直接进入grpc根目录,然后在控制台make即可

$ make

笔者编译的时候,遇到的一些问题

编译protobuf的时候失败, 提示

config.status: error: cannot find input file: `Makefile.in'

这个时候,进入protobuf源码文件, 运行autogen.sh脚本,然后再返回到grpc源码根目录,继续编译即可

$ cd ./third_party/protobuf

$ ./autogen.sh

没有自动编译zlib库

编译grpc库的时候,并没有自动编译zlib库,所有需要自己手动去编译下

$ cd ./third_party/zlib

$ mdkir .build

$ cd .build

$ cmake ..

$ make

4. 使用

第一次测试使用的话,可以使用example里面的helloworld

先根据helloworld.proto生成pb和grpc.pb文件$ protoc.exe -I=. --grpc_out=../pb_gen --plugin=protoc-gen-grpc=../../.../../YDK/3rd/grpc-1.15.0/bin/linux/grpc_cpp_plugin helloworld.proto

$ protoc.exe -I=. --cpp_out=../pb_gen helloworld.proto

protoc-gen-grpc 后面跟的是grpc_cpp_plugin二进制路径, 然后在pb_gen文件夹会生成4个文件

helloworld.grpc.pb.h

helloworld.grpc.pb.cc

helloworld.pb.cc

helloworld.pb.h

CMakelist.txt

代码路径

grpc_test

|----bin

|----pb_gen

|----helloworld.grpc.pb.cc

|----helloworld.grpc.pb.h

|----helloworld.pb.cc

|----helloworld.pb.h

|----src

|----client

|-----greeter_client.cc

|----server

|-----greeter_server.cc

|----projects

|----cmake

|----CMakeLists.txt

CMakelist.txt

cmake_minimum_required(VERSION 2.6)

project(grpc_test)

#add_compile_options(-std=c++11)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -march=native -O3 -pthread")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ../../../bin/)

# client

set(CLI_HEADER_SRCS

../../pb_gen/helloworld.grpc.pb.h

../../pb_gen/helloworld.pb.h

)

set(CLI_CPP_SRCS

../../pb_gen/helloworld.grpc.pb.cc

../../pb_gen/helloworld.pb.cc

../../src/client/greeter_client.cc

)

include_directories(

../../src

../../pb_gen

../../../../../YDK/3rd/protobuf-3.5.1/include

../../../../../YDK/3rd/grpc-1.15.0/include

../../../../../YDK/

)

add_executable(grpc_test_client ${CLI_HEADER_SRCS} ${CLI_CPP_SRCS})

FIND_LIBRARY(PB_LIB protobuf ../../../../../YDK/3rd/protobuf-3.5.1/lib/linux)

message(STATUS "protobuf lib path:" ${PB_LIB})

if(NOT PB_LIB)

message(FATAL_ERROR "not find the protobuf lib" )

endif(NOT PB_LIB)

FIND_LIBRARY(ADDR_SORT_LIB address_sorting ../../../../../YDK/3rd/grpc-1.15.0/lib/linux)

message(STATUS "address_sorting lib path:" ${ADDR_SORT_LIB})

if(NOT ADDR_SORT_LIB)

message(FATAL_ERROR "not find the address_sorting lib" )

endif(NOT ADDR_SORT_LIB)

FIND_LIBRARY(ARES_LIB ares ../../../../../YDK/3rd/grpc-1.15.0/lib/linux)

message(STATUS "ares lib path:" ${ARES_LIB})

if(NOT ARES_LIB)

message(FATAL_ERROR "not find the ares lib" )

endif(NOT ARES_LIB)

FIND_LIBRARY(BSSL_LIB boringssl ../../../../../YDK/3rd/grpc-1.15.0/lib/linux)

message(STATUS "boringssl lib path:" ${BSSL_LIB})

if(NOT BSSL_LIB)

message(FATAL_ERROR "not find the boringssl lib" )

endif(NOT BSSL_LIB)

FIND_LIBRARY(GPR_LIB gpr ../../../../../YDK/3rd/grpc-1.15.0/lib/linux)

message(STATUS "gpr lib path:" ${GPR_LIB})

if(NOT GPR_LIB)

message(FATAL_ERROR "not find the gpr lib" )

endif(NOT GPR_LIB)

FIND_LIBRARY(GRPC_LIB grpc ../../../../../YDK/3rd/grpc-1.15.0/lib/linux)

message(STATUS "grpc lib path:" ${GRPC_LIB})

if(NOT GRPC_LIB)

message(FATAL_ERROR "not find the grpc lib" )

endif(NOT GRPC_LIB)

FIND_LIBRARY(GRPCPP_LIB grpc++ ../../../../../YDK/3rd/grpc-1.15.0/lib/linux)

message(STATUS "grpc++ lib path:" ${GRPCPP_LIB})

if(NOT GRPCPP_LIB)

message(FATAL_ERROR "not find the grpc++ lib" )

endif(NOT GRPCPP_LIB)

FIND_LIBRARY(ZLIB_LIB z ../../../../../YDK/3rd/grpc-1.15.0/lib/linux)

message(STATUS "zlib lib path:" ${ZLIB_LIB})

if(NOT ZLIB_LIB)

message(FATAL_ERROR "not find the zlib lib" )

endif(NOT ZLIB_LIB)

target_link_libraries(grpc_test_client ${PB_LIB} ${GRPCPP_LIB}

${GRPC_LIB} ${GPR_LIB} ${BSSL_LIB} ${ARES_LIB} ${ADDR_SORT_LIB} ${ZLIB_LIB})

# server

set(SRV_HEADER_SRCS

../../pb_gen/helloworld.grpc.pb.h

../../pb_gen/helloworld.pb.h

)

set(SRV_CPP_SRCS

../../pb_gen/helloworld.grpc.pb.cc

../../pb_gen/helloworld.pb.cc

../../src/server/greeter_server.cc

)

include_directories(

../../src

../../pb_gen

../../../../../YDK/3rd/protobuf-3.5.1/include

../../../../../YDK/3rd/grpc-1.15.0/include

../../../../../YDK/

)

# link dir

# link_directories(../../../../../YDK/3rd/grpc-1.15.0/lib/linux)

add_executable(grpc_test_server ${SRV_HEADER_SRCS} ${SRV_CPP_SRCS})

FIND_LIBRARY(PB_LIB protobuf ../../../../../YDK/3rd/protobuf-3.5.1/lib/linux)

message(STATUS "protobuf lib path:" ${PB_LIB})

if(NOT PB_LIB)

message(FATAL_ERROR "not find the protobuf lib" )

endif(NOT PB_LIB)

target_link_libraries(grpc_test_server ${PB_LIB}

${GRPCPP_LIB} ${GRPC_LIB} ${GPR_LIB} ${BSSL_LIB} ${ARES_LIB} ${ADDR_SORT_LIB} ${ZLIB_LIB})

依赖的库有

libprotobuf.lib

libgrpc++.lib

libgrpc.lib

libgpr.lib

libboringssl.lib

libares.lib

libaddress_sorting.lib

libz.lib

编译$ cd ./projects/cmake

$ mkdir .build

$ cd .build

$ cmake ..

$ make

运行

server

$ ./grpc_test_server

Server listening on 0.0.0.0:50051

client

$ ./grpc_test_client

Greeter received: Hello world

linux grpc,grpc linux下的编译使用-Go语言中文社区相关推荐

  1. linux环境搭建golang服务器,Linux下golang环境搭建-Go语言中文社区

    1.首先从使用wget https://storage.googleapis.com/golang/go1.12.linux-amd64.tar.gz命令下载安装包,可以根据自己的需要选择版本. 2. ...

  2. linux ftp ssl客户端,Linux下ftp+ssl实现ftps-Go语言中文社区

    ftps与sftp: FTPS是借助ssl协议加密,ssl是为http/smtp等加密设计的::SFTP是借助ssh加密,ssh是为telnet/ftp等加密.建立传输通道而设计的.ssh建立传输通道 ...

  3. linux 设置 java.library.path,Linux下修改java.library.path-Go语言中文社区

    第一步:打印出当前的java.library.path有哪些目录: 执行  vi  Test.java 切换编辑模式  i 插入如下代码: public class Test { public sta ...

  4. c语言编译及下载环境变量,windows 下使用g++ 编译器-Go语言中文社区

    转自https://blog.csdn.net/xiaoliuliu2050/article/details/53420792 名词解释:GNU("Gnu's Not Unix"的 ...

  5. windows和linux添加引导文件,Linux与Windows 10用grub引导教程-Go语言中文社区

    前言 去年暑假的时候,写了一篇如何装 Linux 和 Windows 10 双系统的文章发在了简书上,我写这篇文章的原因是当初装双系统确实是折腾了许久,网上也找不到一篇详尽的教程.由于去年对于写教程还 ...

  6. WSL安装Oracle,折腾记录:WSL(Windows Subsystem for Linux,Windows上的Linux子系统)安装后的环境配置-Go语言中文社区...

    WSL(Windows Subsystem for Linux,Windows上的Linux子系统)的安装比较简单,教程网上较多,此处略过.安装后须要进行一系列配置(如软件源配置.中文配置.图形化配置 ...

  7. dockerfile构建mysql_Dockerfile在linux上构建mysql8镜像并创建数据库-Go语言中文社区

    由于mysql5和mysql8版本的不同,导致构建镜像的时候存在一定的差异,在此将mysql8镜像的构建做一个总结. 本次总共用到了四个文件,分别是Dockerfile,setup.sh,my.sql ...

  8. linux sar使用方法,Linux系列之SAR命令使用详解-Go语言中文社区

    1. CPU利用率 sar -p (查看全天) sar -u 1 10 (1:每隔一秒,10:写入10次) 1.1. CPU输出项说明 输出项 详细说明 CPU all 表示统计信息为所有 CPU 的 ...

  9. 源码包编译安装python_Python3.7源码包编译安装-Go语言中文社区

    环境: [root@localhost python3]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@loc ...

最新文章

  1. HALCON示例程序count_pellets.hdev分割豆子,基本形态学的使用
  2. 2021牛客暑期多校训练营2 B-Cannon(组合+推式子)
  3. 字符串数组判断数字,字母汉字,
  4. 安卓手机管理软件_日程管理软件哪个好?
  5. 2020年华工计算机应用基础随堂作业,《计算机应用基础》随堂练习-2020年华工网络教育.docx...
  6. C#交错数组与多维数组区别
  7. 窗方法原理之矩形窗及汉明窗
  8. 计算机进入安全模式的原因,电脑只能进入安全模式的原因及处理方法
  9. java计算机毕业设计游泳馆信息管理系统源程序+mysql+系统+lw文档+远程调试
  10. HTTP(S) 路由器 fabio
  11. CCF-CSP 201403-1 相反数 (python)
  12. 计算机 哈弗结构图,作为一个程序员,不知道什么是冯诺依曼体系结构?那肯定也不知道哈佛结构喽!...
  13. 英语计算机主板接口有,主板上常见英文的解释
  14. Erasure Code - EC纠删码原理
  15. C++求1-20的阶乘之和
  16. depot_tools官方文档+工具包下载
  17. Linux 高性能服务器网络编程(一)
  18. Semantic Segmentation -- (DeepLabv3)Rethinking Atrous Convolution for Semantic Image Segmentation论文解
  19. 七牛---借助第三方平台实现移动直播
  20. RFC3164 – BSD Syslog协议

热门文章

  1. window环境下mysql配置参数_Window下mysql环境配置问题整理
  2. APP长期处于后台手机打开多个APP后进程被杀
  3. Android开发之ConstraintLayout(约束布局)一个控件位于一个控件右上角类似RelativeLayout实现效果
  4. Android开发之Java基础面试题抽象类和接口的区别
  5. c语言编程运动会分数统计系统报告,独家稿件:定稿运动会分数统计系统设计报告_完整版...
  6. NSLog中格式符列表
  7. AppStore发布产品步骤
  8. linux fpga通信,基于Linux的FPGA通信技术研究与实现
  9. .NET环境下每日集成(4):CruiseControl.Net配置注意事项
  10. 用python查找指定格式或名称的文件及修改指定文件夹名称