linux下安装protobuf教程+示例(详细)
看这个就应该知道是没有找到头文件,那么可以使用g++ 的-I 参数:
-I/usr/local/lib/protobuf/include来命令g++在/usr/local/lib/protobuf下查找头文件
以上/usr/local/lib/protobuf/是我的protobuf的安装地址,请替换成你的
5> 写消息文件:msg.proto
- package lm;
- message helloworld
- {
- required int32 id = 1; // ID
- required string str = 2; // str
- optional int32 opt = 3; //optional field
- }
- #include "msg.pb.h"
- #include <fstream>
- #include <iostream>
- using namespace std;
- int main(void)
- {
- lm::helloworld msg1;
- msg1.set_id(101);
- msg1.set_str("hello");
- fstream output("./log", ios::out | ios::trunc | ios::binary);
- if (!msg1.SerializeToOstream(&output)) {
- cerr << "Failed to write msg." << endl;
- return -1;
- }
- return 0;
- }
- #include "msg.pb.h"
- #include <fstream>
- #include <iostream>
- using namespace std;
- void ListMsg(const lm::helloworld & msg) {
- cout << msg.id() << endl;
- cout << msg.str() << endl;
- }
- int main(int argc, char* argv[]) {
- lm::helloworld msg1;
- {
- fstream input("./log", ios::in | ios::binary);
- if (!msg1.ParseFromIstream(&input)) {
- cerr << "Failed to parse address book." << endl;
- return -1;
- }
- }
- ListMsg(msg1);
- }
8> 写Makefile文件
- all: write reader
- clean:
- rm -f write reader msg.*.cc msg.*.h *.o log
- proto_msg:
- protoc --cpp_out=. msg.proto
- write: msg.pb.cc write.cc
- g++ msg.pb.cc write.cc -o write `pkg-config --cflags --libs protobuf`
- reader: msg.pb.cc reader.cc
- g++ msg.pb.cc reader.cc -o reader `pkg-config --cflags --libs protobuf`
linux下安装protobuf教程+示例(详细)的更多相关文章
- Linux下安装GB2312的示例
Linux下安装GB2312的示例 Step 1: 到Linux字符集的安装包目录下 [cd /usr/share/i18n/charmaps] Step 2: 解压该目录下的GB2312.gz ...
- Linux下安装mysql教程
Linux下安装mysql MySQL官网:https://dev.mysql.com/downloads/mysql/ 到mysql官网下载mysql编译好的二进制安装包,在下载页面Select ...
- Linux下安装protobuf并实现简单的客户端服务器端通信
http://code.google.com/p/protobuf/downloads/list上可以下载Protobuf的源代码. 安装步骤如下所示: 1>tar -xzf protobuf- ...
- linux下 安装mysql教程
安装环境:系统是 centos6.5 1.下载 下载地址:http://dev.mysql.com/downloads/mysql/5.6.html#downloads 下载版本:我这里选择的5.6. ...
- Linux下安装mysql-5.7.28详细步骤
一.下载Mysql 下载地址:https://downloads.mysql.com/archives/community/ 二.环境配置 检测系统是否自带Mysql # rmp -qa|grep m ...
- linux下安装protobuf及cmake编译
一.protobuf 安装 protobuf版本:2.6.1 下载地址:https://github.com/google/protobuf/archive/v2.6.1.zip 解压之后进入目录 修 ...
- linux下安装mysql5.7.25详细教程
前言 最近项目上线,开始给用户测试了.搞下来好多台服务器,自然要装一个mysql的服务器.想想广大博友应该都会遇到如何装mysql的问题,就此分享,给大家一个安装指南.供大家以后安装的时候,提高效率, ...
- Linux下安装mysql(示例mysql5.6安装)
1.首先检查你的linux上是否已经安装了mysql rpm -qa|grep mysql 2.如果mysql的版本不是想要的版本.需要把mysql卸载 yum remove mysql mysql- ...
- Linux下安装Nginx教程
什么是Nginx? Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,在高连接并发的情况下N ...
随机推荐
- hive添加分区
添加分区 alter table 表名 add partition (dt='2016-09-12'); select * from 表名 where dt = '2016-09-12' limit ...
- oracle通过DBlink连接mysql(MariaDB)
1.安装先装 mysql-connector-odbc(或 mariadb-connector-odbc )和unixODBChttps://downloads.mariadb.org/mariadb ...
- javascript创建对象的相关问题
javascript创建对象的方法有很多种,一般来说,推荐使用对象字面量来创建对象. 对象构造函数捕捉 使用new Object来创建对象,可能会带来一些问题: var o = new Object( ...
- JDBC链接MySQL和Oracle
import java.sql.*; JDBC中所要用的包几乎都在import?java.sql.*;中: 在项目中导入Oracel或者是MySQL包和装载驱动: 项目的Cla ...
- div模仿select效果二:带搜索框
项目需要,要做一个首字母快速定位的select,代码如下: HTML <div class="select_country" unselectable="on&qu ...
- 跨域请求之JSONP 二
续上篇,加两个实用功能 1,增加data属性,请求参数2,增加scope属性,可以让回调函数在指定的上下文中执行 接口如下 1 2 3 4 5 6 Sjax.load(url, { data ...
- Android IOS WebRTC 音视频开发总结(十)-- webrtc入门002
继续上一篇中未翻译完成的部分,主要包括下面三个部分: 1,扩展:WebRTC多方通话. 2,MCU Multipoint Control Unit. 2, 扩展:VOIP,电话,消息通讯. 注意:翻译 ...
- 详解Oracle临时表的几种用法及意义
Oracle临时表可以说是提高数据库处理性能的好方法,在没有必要存储时,只存储在Oracle临时表空间中.希望本文能对大家有所帮助. 1 .前言 Oracle Logo 目前所有使用 Oracle 作 ...
- spark-submit工具参数说明
执行时需要传入的参数说明 Usage: spark-submit [options] <app jar | python file> [app options] 参数名称 含义 --mas ...
- js一些实用例子
1.获取焦点选中文本内容 $("#id").focus(function(){ this.select(); }); 2.表单提交方式 A.自动提交 setTimeout(func ...