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

protobuf安裝

系統 1819 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條評論
主站蜘蛛池模板: 在线中文字幕视频 | 四虎影院免费 | 欧美精品四虎在线观看 | 成人久久18免费网址 | 日韩黄色网页 | 色偷偷要色偷偷网站视频在线 | 久久经典 | 四虎永久免费在线 | 宅男影院在线观看 | 日本aaaa毛片在线看 | 妞干网中文字幕 | 国产成人毛片亚洲精品不卡 | 婷婷综合激情 | 国产精品v免费视频 | 日日干日日操日日射 | 久久看免费视频 | 成人在色线视频在线观看免费大全 | 国产一级在线观看www色 | 久久99热精品免费观看k影院 | 欧美久久久久久久一区二区三区 | 成人激情小视频 | 四虎永久在线观看视频精品 | 日本在线 | 中文 | 草久视频在线 | 五月激情婷婷综合 | 色婷婷5月精品久久久久 | 国产成人亚洲精品老王 | 狠狠色噜噜狠狠狠合久 | 日韩一区二区中文字幕 | 综合精品在线 | 成人国产欧美精品一区二区 | 免费观看毛片 | 免费又黄又爽视频 | 国产精品日韩欧美一区二区三区 | 精品视频一区二区三区在线播放 | a一级网站 | 国产尤物福利视频一区二区 | 国产精品66 | 日韩午夜伦 | 成年女人免费观看视频 | 国产精品久久久久久久久岛 |