惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Spread Privacy
Spread Privacy
T
Troy Hunt's Blog
Recent Announcements
Recent Announcements
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Schneier on Security
罗磊的独立博客
T
The Exploit Database - CXSecurity.com
博客园 - 司徒正美
月光博客
月光博客
C
Cybersecurity and Infrastructure Security Agency CISA
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Project Zero
Project Zero
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Latest news
Latest news
L
Lohrmann on Cybersecurity
阮一峰的网络日志
阮一峰的网络日志
C
CERT Recently Published Vulnerability Notes
腾讯CDC
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
T
Threat Research - Cisco Blogs
T
Tenable Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - Franky
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
Attack and Defense Labs
Attack and Defense Labs
C
Cyber Attacks, Cyber Crime and Cyber Security
V
V2EX
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
Scott Helme
Scott Helme
小众软件
小众软件
L
LINUX DO - 最新话题
博客园 - 叶小钗
博客园 - 【当耐特】
PCI Perspectives
PCI Perspectives
SecWiki News
SecWiki News
S
Security Affairs
P
Palo Alto Networks Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
SegmentFault 最新的问题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园 - 聂微东
量子位
C
CXSECURITY Database RSS Feed - CXSecurity.com
Help Net Security
Help Net Security
S
Secure Thoughts
S
Securelist

博客园 - xcywt

IT人备考心得分享 一个大龄程序员的回乡记 一种刚接触的语法。只在linux可用 固件打包流程 malloc底层实现以及和new的比较 C++异步调用 future async promise packaged_task 如果在单例模式中返回share_ptr ??? 记录一道面试题(哈希表 稀疏矩阵) Qt实现自定义控件-按钮 一个线程池的例子 C++ 条件变量condition_variable的例子 C++中share_ptr中循环引用的问题 C++14的一些新特性 C++11的一些特性 perf笔记 一个cmakelist的例子(自动处理多个proto) Linux下eCal测试计划及进度记录 windows编译ecal 记录一次重装gitlab
ubuntu编译grpc & protobuf
xcywt · 2024-09-18 · via 博客园 - xcywt

参考:Ubuntu系统中本地编译并安装grpc的C++版本及测试 - 知乎 (zhihu.com)

安装依赖:

# 这些可能都已经安装了
sudo apt-get install pkg-config autoconf automake libtool make g++ unzip
# 下面的可能没安装
sudo apt-get install libgflags-dev libgtest-dev 
sudo apt-get install clang libc++-dev

下载源码:

git clone -b v1.36.4 https://github.com/grpc/grpc.git
cd grpc
# 下载其依赖的子模块
git submodule update --init

先编译安装protobuf:

# 此时应在grpc文件夹下
cd third_party/protobuf/
# 更新依赖的子模块
git submodule update --init --recursive
# 生成配置脚本
sudo ./autogen.sh   
# 生成makefile文件
sudo ./configure
# 从makefile读取指令编译
sudo make
# 可能报错,但不影响安装
sudo make check
# 安装
sudo make install
# 更新共享库缓存
sudo ldconfig
# 查看安装的位置
which protoc
#查看是否安装成功,这里输出的protoc版本应该是3.14.0
protoc --version

继续安装grpc:

 进入到grpc文件夹下# 创建编译文件夹
mkdir -p cmake/build
cd cmake/build
cmake ../..
# 编译
make -j3
# 安装
sudo make install

测试安装成功与否:

# 进入grpc文件夹下
cd examples/cpp/helloworld
mkdir build
cd build
# 编译
cmake ..
make

# 编译完成后,在文件夹下就生成了可执行文件,先执行
./greeter_server
# 再新开终端,执行
./greeter_client
# 会输出:Greeter received: Hello world
# 即安装成功

如何使用:

参考上述示例中的cmakelist中的写法,在自己的项目中包含 common.cmake。 可以把这个common.cmake拷贝到自己工程中。

包含后,再显式链接一下相关库: