IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> grpc|protobuf的安装、编译、运行笔记(C++) -> 正文阅读

[开发工具]grpc|protobuf的安装、编译、运行笔记(C++)

一、下载grpc源码

如果你的电脑/服务器可以做代理,然后稳定链接上 GitHub 那么完全可以按照 GitHub 的官方文档来操作,我这里采用 Gitee 镜像来操作

git clone https://gitee.com/jiangxy__loey/grpc.git

在这里插入图片描述

二、下载依赖库

进入grpc目录,然后里面有一个 .gitmodules 文件,我们将其替换成 gitee 的链接,首先清空内容

> .gitmodules

然后再将新内容填入:

[submodule "third_party/zlib"]
	path = third_party/zlib
	#url = https://github.com/madler/zlib
	url = https://gitee.com/jiangxy__loey/zlib.git
	# When using CMake to build, the zlib submodule ends up with a
	# generated file that makes Git consider the submodule dirty. This
	# state can be ignored for day-to-day development on gRPC.
	ignore = dirty
[submodule "third_party/protobuf"]
	path = third_party/protobuf
	url = https://gitee.com/jiangxy__loey/protobuf.git
	#url = https://github.com/google/protobuf.git
[submodule "third_party/gflags"]
	path = third_party/gflags
	#url = https://github.com/gflags/gflags.git
	url = https://gitee.com/jiangxy__loey/gflags.git
[submodule "third_party/benchmark"]
	path = third_party/benchmark
	#url = https://github.com/google/benchmark
	url = https://gitee.com/jiangxy__loey/benchmark.git
[submodule "third_party/boringssl-with-bazel"]
	path = third_party/boringssl-with-bazel
	#url = https://github.com/google/boringssl.git
	url = https://gitee.com/jiangxy__loey/boringssl-with-bazel.git
[submodule "third_party/re2"]
	path = third_party/re2
	#url = git://github.com/google/re2.git
	url = https://gitee.com/hejuncheng1/re2.git
[submodule "third_party/cares/cares"]
	path = third_party/cares/cares
	#url = https://github.com/c-ares/c-ares.git
	url = https://gitee.com/jiangxy__loey/cares.git
	#branch = cares-1_12_0
[submodule "third_party/bloaty"]
	path = third_party/bloaty
	#url = https://github.com/google/bloaty.git
	url = https://gitee.com/jiangxy__loey/bloaty.git
[submodule "third_party/abseil-cpp"]
	path = third_party/abseil-cpp
	#url = https://github.com/abseil/abseil-cpp.git
	url = https://gitee.com/jiangxy__loey/abseil-cpp.git
	branch = lts_2020_02_25
[submodule "third_party/envoy-api"]
	path = third_party/envoy-api
	#url = https://github.com/envoyproxy/data-plane-api.git
	url = https://gitee.com/jiangxy__loey/envoy-api.git
[submodule "third_party/googleapis"]
	path = third_party/googleapis
	#url = https://github.com/googleapis/googleapis.git
	url = https://gitee.com/jiangxy__loey/googleapis.git
[submodule "third_party/protoc-gen-validate"]
	path = third_party/protoc-gen-validate
	#url = https://github.com/envoyproxy/protoc-gen-validate.git
	url = https://gitee.com/jiangxy__loey/protoc-gen-validate.git
[submodule "third_party/udpa"]
	path = third_party/udpa
	#url = https://github.com/cncf/udpa.git
	url = https://gitee.com/jiangxy__loey/udpa.git
[submodule "third_party/libuv"]
	path = third_party/libuv
	#url = https://github.com/libuv/libuv.git
	url = https://gitee.com/jiangxy__loey/libuv.git

然后下载:

git submodule update --init

在这里插入图片描述

当然如果如果说你的电脑不能科学上网或者上面的操作报错了,说明电脑网络有问题,可以直接下载这个继续操作:
链接:https://pan.baidu.com/s/1sPFO5jXKBJnbNQwiWCLQEw?pwd=wmak
提取码:wmak

四、安装工具和环境依赖

sudo apt-get install pkg-config
sudo apt-get install autoconf automake libtool make g++ unzip
sudo apt-get install libgflags-dev libgtest-dev
sudo apt-get install clang libc++-dev

五、编译protobuf

进入grpc/third_party/protobuf 目录,然后给 autogen.sh 文件加上执行权限:

chmod +x autogen.sh

因为是在 gitee 下载的文件,所以文本格式为 PC,我们需要将其转化为 unix,否则编译会报错,我们通过借助dos2unix工具转换

  • 下载工具
apt install dos2unix

在这里插入图片描述

  • grpc/third_party/protobuf 目录下对所有文件进行格式转换
dos2unix  *

在这里插入图片描述

此时格式替换完成,我们就可以开始编译 protobuf 了,执行 autogen.sh 脚本即可

./autogen.sh

在这里插入图片描述

假设新建库的输出路径 /usr/local
设置库的输出路径

./configure --prefix=/usr/local

开始编译(可能会编的有点久,看个人机器)

make
make check
sudo make install
sudo ldconfig  # 使得新安装的动态库能被加载

protoc --version
显示3.19.4

注意,在这一步可能会遇到找不到gawk 的情况
我们只需要apt安装即可

apt install gawk

编译完成后此时我们进入/home/mangata/grpc_learn/grpc/protobuf,然后输出一下当前的目录结构:

在这里插入图片描述

到这里, protobuf 编译完成,接下来就是编译 grpc

六、编译grpc

我们回到 grpc/ 这个路径,然后执行下面的操作即可完成

mkdir -p cmake/build
cd cmake/build
cmake ../..
make
sudo make install

sudo make install 报错了,那就去 /usr/local/share/man/ 目录将man1 删掉,并且创建一个man1 的文件夹
在这里插入图片描述
在这里插入图片描述

七、测试

进入grpc/examples/cpp/helloworld 目录,然后创建build 文件夹

cd grpc/examples/cpp/helloworld/
mkdir build
cd build/
cmake ..
make

进入 build 文件夹cd build ,然后cmake .. ,最后输入 make

在这里插入图片描述

在这里插入图片描述

启动服务和客户端

# 启动服务端,监听在50051端口
./greeter_server
Server listening on 0.0.0.0:50051
# 启动客户端,服务端返回Hello world
./greeter_client 
Greeter received: Hello world

在这里插入图片描述
看到回应 Hello world 就完成了,接下来就是学习 grpc 的四种模式了,下期再见~

  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2022-09-13 11:38:53  更:2022-09-13 11:40:15 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/18 16:23:30-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码