- Install Protocal Buffer
- Please read the readmes. Running "make install" in the root directory installs the C++ libraries only. You need to install the Java and Python versions separately by following the instructions in the corresponding directories.
- https://groups.google.com/forum/#!topic/protobuf/60-OFrBXlAE
- How to start from protocol buffer
- Check example code from source code package.
- https://github.com/google/protobuf/tree/master/examples
- Including source for java, c++, and python
- Examples
- CPP
- protoc_middleman: addressbook.proto
- protoc --cpp_out=. --java_out=. --python_out=. addressbook.proto
- @touch protoc_middleman
- protoc_middleman_go: addressbook.proto
- mkdir tutorial # make directory for go package
- protoc --go_out=tutorial addressbook.proto
- @touch protoc_middleman_go
- add_person_cpp: add_person.cc protoc_middleman
- pkg-config --cflags protobuf # fails if protobuf is not installed
- c++ add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf`
- pkg-config --cflags --libs protobuf
- pkg-config - Return metainformation about installed libraries
- The pkg-config program is used to retrieve information about installed libraries in
- the system. It is typically used to compile and link against one or more libraries.
- Here is a typical usage scenario in a Makefile:
- program: program.c
- cc program.c 'pkg-config --cflags --libs gnomeui'
- `pkg-config --cflags --libs protobuf ` returns
- -lprotobuf -lz -lpthread on centos
- -pthread -pthread -lprotobuf -lpthread on ubuntu 14.04
- "Package protobuf was not found in the pkg-config search path." if it is not installed
- Generated:
- add_person_cpp
- list_people_cpp
- Run this file, returned with:
- Person ID: 1
- Name: Charles
- E-mail address: charles@gmail.com
- Home phone #: 541 346 1380
- Python
- Error: ImportError: No module named google.protobuf
- sudo pip install protobuf
- Java
- make Error: package com.google.protobuf does not exist
- need protobuf-java-*.jar
Saturday, May 14, 2016
[Language] Playing with protocol buffer
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment