sourcecode

Monday, July 8, 2013

protoc protobuf Protocol Buffers

This blog entry lists the process to use google's Protoco Buffers, on x64 Linux Mint 14.

1. Download protobuf-2.5.0.tar.bz2 from
https://code.google.com/p/protobuf/downloads/list


2.  Extract the file anywhere.

3. Under the extracted folder, run
$./configure
$make
$make check
$sudo make install

4.  View the README file in the folder, and test some common:
  $pkg-config --cflags protobuf         # print compiler flags
  $pkg-config --libs protobuf           # print linker flags
  $pkg-config --cflags --libs protobuf  # print both


5.  Download a proto file. e.g. from
https://developers.google.com/transit/gtfs-realtime/gtfs-realtime-proto

6.  Go to the proto file folder and generate the C++ header and source file:
$protoc gtfs-realtime.proto --cpp_out=./
Ref: https://developers.google.com/protocol-buffers/docs/proto


7. If there are some errors, check the environment variables 
$export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib   $export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
Ref:  http://blog.csdn.net/programmer_h/article/details/8890800


8.  Write a sample main file:
#include <iostream>
#include <string>
#include <fstream>
#include "gtfs-realtime.pb.h"
using namespace std;

int main()
{
   fstream file("alert2.dat");
   string outline;
   getline(file, outline);
   cout <&lt outline << endl;
}

9. Download a sample encoded binary data file: e.g.
 http://www.bart.gov/dev/gtrtfs/alerts.aspx


10. Compile:
$clang++ main.cpp gtfs-realtime.pb.cc `pkg-config --cflags --libs protobuf`


No comments: