亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

protobuf安裝

系統 1593 0
1 在網站 http://code.google.com/p/protobuf/downloads/list上可以下載 Protobuf 的源代碼。然后解壓編譯安裝便可以使用它了。
安裝步驟如下所示:
?
也可在https://github.com/google/protobuf/releases/tag/v3.0.0-alpha-3 上面下載這個,我是從上面的網站直接跳轉過來的找到的
?
提取 protobuf-3.0.0-alpha-3
?cd protobuf-3.0.0-alpha-3
sudo sh ./autogen.sh
?./configure --prefix=/usr/local/protobuf
?make?
?make check?
?make install?
?
?2 > sudo vim /etc/profile
?添加
export PATH=$PATH:/usr/local/protobuf/bin/
export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/
保存執行
source /etc/profile
?
同時 在~/.profile中添加上面兩行代碼,否則會出現登錄用戶找不到protoc命令
?
3 > 配置動態鏈接庫路徑
sudo vim /etc/ld.so.conf
插入:
/usr/local/protobuf/lib
?
4 > su ?#root 權限
ldconfig
?

5> 寫消息文件:msg.proto

  1. package?lm;???
  2. message?helloworld???
  3. {???
  4. ????required?int32?????id?=?1;??//?ID?????
  5. ????required?string????str?=?2;??//?str????
  6. ????optional?int32?????opt?=?3;??//optional?field???
  7. }??
將消息文件msg.proto映射成cpp文件
protoc -I=. --cpp_out=. msg.proto
可以看到生成了
msg.pb.h 和msg.pb.cc
?
6> 寫序列化消息的進程
write.cc
  1. #include?"msg.pb.h"??
  2. #include?<fstream>??
  3. #include?<iostream>??
  4. using?namespace?std;??
  5. ??
  6. int?main(void)???
  7. {???
  8. ??
  9. ????lm::helloworld?msg1;???
  10. ????msg1.set_id(101);???
  11. ????msg1.set_str("hello");???
  12. ????fstream?output("./log",?ios::out?|?ios::trunc?|?ios::binary);???
  13. ??
  14. ????if?(!msg1.SerializeToOstream(&output))?{???
  15. ????????cerr?<<?"Failed?to?write?msg."?<<?endl;???
  16. ????????return?-1;???
  17. ????}??????????
  18. ????return?0;???
  19. }??
編譯 write.cc?
?g++ ?msg.pb.cc write.cc -o write ?`pkg-config --cflags --libs protobuf` -lpthread
?
執行write?
./write, 可以看到生成了log文件
?
7> 寫反序列化的進程
reader.cc
  1. #include?"msg.pb.h"??
  2. #include?<fstream>??
  3. #include?<iostream>??
  4. using?namespace?std;??
  5. ??
  6. void?ListMsg(const?lm::helloworld?&?msg)?{????
  7. ????cout?<<?msg.id()?<<?endl;???
  8. ????cout?<<?msg.str()?<<?endl;???
  9. }???
  10. ??
  11. int?main(int?argc,?char*?argv[])?{???
  12. ??
  13. ????lm::helloworld?msg1;???
  14. ??
  15. ????{???
  16. ????????fstream?input("./log",?ios::in?|?ios::binary);???
  17. ????????if?(!msg1.ParseFromIstream(&input))?{???
  18. ????????????cerr?<<?"Failed?to?parse?address?book."?<<?endl;???
  19. ????????????return?-1;???
  20. ????????}?????????
  21. ????}???
  22. ??
  23. ????ListMsg(msg1);???
  24. }??
編譯:g++ ?msg.pb.cc reader.cc -o reader ?`pkg-config --cflags --libs protobuf` -lpthread
執行./reader 輸出 :
101
hello

8> 寫Makefile文件

  1. all:?write?reader??
  2. ??
  3. clean:??
  4. ????rm?-f?write?reader?msg.*.cc?msg.*.h?*.o??log??
  5. ??
  6. proto_msg:??
  7. ????protoc?--cpp_out=.?msg.proto??
  8. ??
  9. ??
  10. write:?msg.pb.cc?write.cc??
  11. ????g++??msg.pb.cc?write.cc?-o?write??`pkg-config?--cflags?--libs?protobuf`??
  12. ??
  13. reader:?msg.pb.cc?reader.cc??
  14. ????g++??msg.pb.cc?reader.cc?-o?reader??`pkg-config?--cflags?--libs?protobuf`??

protobuf安裝


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 精品久久久久亚洲 | 欧美精品亚洲人成在线观看 | 国产午夜影院 | 久久精品香蕉视频 | 久久久久99精品成人片三人毛片 | 久久亚洲精品国产亚洲老地址 | 二区在线观看 | 久久国产精品亚洲77777 | 亚洲精品丝袜在线一区波多野结衣 | 99在线精品免费视频九九视 | 天然素人在线观看 | 日本人一级毛片视频 | 99热这里只有精品第一页 | 四虎影永久在线高清免费 | 伊人色综 | 日日操天天操夜夜操 | 999国产精品视频 | 日韩中文字幕推理片 | 成人在线免费观看 | 夜夜操天天爽 | 国产美女一级高清免费观看 | 日韩午夜在线视频 | 日本色色网| 中文字幕一二区 | 亚洲综合性图 | 青青青青在线成人视99 | 欧美日韩亚洲国产精品一区二区 | 日韩精品一区二区三区高清 | 中文字幕亚洲区 | 亚洲人成网i8禁止 | 国产精品免费一区二区三区 | 在线国产区 | 91精品欧美产品免费观看 | 80岁老妇xxxxx高清 | 久久这里只有精品9 | 亚洲日韩中文字幕 | 久久五月天综合 | 欧美视频一区二区三区在线观看 | 国产亚洲女人久久久久久 | 中文字幕视频一区二区 | 国产一区二区免费不卡在线播放 |