clash安装
arch
如果是aarch64那么下载arm64位的
如果是x86_64那么下载amd64位的
链接 https://github.com/Dreamacro/clash/releases
wget https://github.com/Dreamacro/clash/releases/download/v1.14.0/clash-linux-amd64-v1.14.0.gz
centos安装
yum -y install autoconf automake libtool
yum -y install gcc gcc-c++
2.解压, tar zxvf protobuf-all-3.5.1.tar.gz.进入解压目录 cd protobuf-3.5.1/
3.安装依赖:sudo yum install autoconf automake libtool
4.生成编译配置文件:./autogen.sh
5.运行配置脚本,指定编译器,./configure
6.编译:make
7.安装:make install
8.更新库:sudo ldconfig
9.测试:protoc --version
vim /etc/ld.so.conf.d/libprotobuf.conf #添加下面内容
/usr/local/lib
#然后执行下面命令
sudo ldconfig
vim /etc/profile # 修改文件 添加下面内容
LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
#执行下面命令
source /etc/profile
新建test.proto文件
syntax = "proto3";
package fixbug;
//定义登录消息类型 name pwd
message LoginRequest
{
string name = 1;
string pwd = 2;
}
message LoginResponse
{
int32 errcode = 1;
string errmsg = 2;
bool success = 3;
}
执行protoc test.proto --cpp_out=./
然后会多出几个文件来
新建main.cc文件
#include "test.pb.h"
#include <iostream>
#include <string>
using namespace fixbug;
using namespace std;
int main(){
//封装了login请求对象的数据
LoginRequest req;
req.set_name("zhang san");
req.set_pwd("123456");
//对象数据序列化 =》char*
std::string send_str;
req.SerializeToString(&send_str);
{
std::cout << send_str.c_str() << std::endl;
}
//从send_str反序列化一个login请求对象
LoginRequest reqB;
if(reqB.ParseFromString(send_str))
{
std::cout << reqB.name() << std::endl;
std::cout << reqB.pwd() << std::endl;
}
return 0;
}
执行编译
g++ main.cc test.pb.cc -lprotobuf
尝试运行 ./a.out