Protobuf(一)[环境搭建]

本文详细介绍了在Ubuntu 18.04 LTS和CentOS 7上搭建Protobuf环境的步骤,包括安装依赖、解决github clone速度问题、克隆与安装protobuf以及测试和获取帮助的完整过程。针对git clone速度慢的问题,推荐使用命令方式或浏览器方式更新hosts文件。安装过程中需要注意及时获取最新的IP地址,并在完成安装后重启网络服务。
摘要由CSDN通过智能技术生成

简介

Protocol Buffers - Google’s data interchange format。
Google Protocol Buffers (简称 Protobuf)是google旗下的一款轻便高效的结构化数据存储格式,平台无关、语言无关、可扩展,可用于通讯协议和数据存储等领域。所以很适合用做数据存储和作为不同应用,不同语言之间相互通信的数据交换格式,只要实现相同的协议格式即同一 proto文件被编译成不同的语言版本,加入到各自的工程中去。这样不同语言就可以解析其他语言通过 protobuf序列化的数据。目前官网提供了 C++,Python,JAVA,GO等语言的支持。google在2008年7月7号将其作为开源项目对外公布。【Go于2009年11月正式宣布推出,故而Protobuf原生并不支持Go语言】

在这里插入图片描述

Protobuf的github网址:

https://github.com/protocolbuffers/protobuf

protobuf的安装参考:

https://github.com/protocolbuffers/protobuf/blob/master/src/README.md

Golang的Protobuf的github地址:

https://github.com/golang/protobuf

1.安装

1.Ubuntu1804LTS

protobuf的安装参考:

https://github.com/protocolbuffers/protobuf/blob/master/src/README.md

1.安装依赖

sudo apt install -y autoconf automake libtool curl wget git make g++ libffi-dev unzip dnsutils gcc 

2.解决github clone 速度

git clone配置的获取的IP是会变动的,需要及时的获取更新。
hosts绑定前:
在这里插入图片描述
hosts绑定后:
在这里插入图片描述

1.nslookup方式【不建议】

1.获取信息

dnsutils中的nslookup工具获得github.com和github.global.ssl.fastly.net域名的ip地址

nslookup github.com
nslookup github.global.ssl.fastly.net
Name:   github.com
Address: 192.30.253.112
Name:   github.global.ssl.fastly.net
Address: 151.101.44.249

在这里插入图片描述
2.追加内容到/etc/hosts

sudo cp /etc/hosts /etc/hosts.backup 
sudo tee -a /etc/hosts <<-'EOF'
192.30.253.112 github.com
151.101.44.249 github.global.ssl.fastly.net
EOF
cat /etc/hosts
sudo /etc/init.d/networking restart

在这里插入图片描述

2.命令方式【推荐】

1.获取信息
github.com

Linux上grep执行不生效,和bsd和GUN协议有关,bsd用grep -oE GUN用grep -oP

curl -skX GET 'https://github.com.ipaddress.com/' | grep -oP '<th>IPv4 Addresses</th><td><ul class="comma-separated"><li>.*?</li>'| grep -oP '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'

在这里插入图片描述
github.global.ssl.fastly.net

Linux上grep执行不生效,和bsd和GUN协议有关,bsd用grep -oE GUN用grep -oP

curl -skX GET 'https://fastly.net.ipaddress.com/github.global.ssl.fastly.net' | grep -oP '<th>IPv4 Addresses</th><td><ul class="comma-separated"><li>.*?</li>'| grep -oP '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' 

在这里插入图片描述
2.追加内容到/etc/hosts

sudo cp /etc/hosts /etc/hosts.backup 
sudo tee -a /etc/hosts <<-'EOF'
140.82.112.3 github.com
199.232.69.194 github.global.ssl.fastly.net
EOF
cat /etc/hosts
sudo /etc/init.d/networking restart 

在这里插入图片描述

3.浏览器方式【推荐】

1.获取信息
浏览器打开

https://github.com.ipaddress.com/

在这里插入图片描述
浏览器打开:

https://fastly.net.ipaddress.com/github.global.ssl.fastly.net

在这里插入图片描述
2.追加内容到/etc/hosts

sudo cp /etc/hosts /etc/hosts.backup 
sudo tee -a /etc/hosts <<-'EOF'
140.82.112.3 github.com
199.232.69.194 github.global.ssl.fastly.net
EOF
cat /etc/hosts
sudo /etc/init.d/networking restart

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要搭建C++的protobuf环境,你需要以下步骤: 1. 首先,确保你已经安装了protoc编译器。你可以通过运行以下命令来检查是否已经安装: ``` protoc --version ``` 如果提示找不到命令,则需要先安装protoc编译器。你可以从protobuf的官方网站下载适合你操作系统的安装包,并按照官方指南进行安装。 2. 然后,你需要在你的C++项目中包含protobuf的头文件。在你的C++源文件中,使用以下代码包含protobuf的头文件: ```cpp #include "google/protobuf/message.h" ``` 这将包含protobuf的基本头文件,以便你可以在你的代码中使用protobuf的相关功能。 3. 接下来,你需要将protobuf库链接到你的项目中。这可以通过在编译命令中添加protobuf的库文件路径和库文件名来完成。例如,你可以使用以下命令来编译和链接你的C++代码: ``` g++ your_code.cpp -o your_executable -lprotobuf ``` 请注意,你需要将`your_code.cpp`替换为你的实际源文件名,`your_executable`替换为你希望生成的可执行文件名。 4. 最后,确保你的C++项目中包含了MsgProtocol.proto文件。这是你定义通信协议的protobuf文件。你可以使用以下命令来生成C++代码: ``` protoc.exe MsgProtocol.proto --cpp_out=./ ``` 请将`MsgProtocol.proto`替换为你的实际.proto文件名,并将`./`替换为你希望生成代码的输出路径。 完成以上步骤后,你就成功搭建了C++的protobuf环境,并可以在你的代码中使用protobuf进行通信了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [cocos2dx 3.x C++搭建protobuf环境](https://blog.csdn.net/ganpengjin1/article/details/50964961)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值