Google Protobuf Learning Note one: Under Windows environment configuration

Source: Internet
Author: User

Welcome reprint, Reproduced please specify the original address: http://blog.csdn.net/majianfei1023/article/details/45371743


Use and principle of protobuf, please view: http://blog.csdn.net/majianfei1023/article/details/45112415

Google PROTOBUF development environment configuration under windows

Recent project requirements, client and Server network communication protocol transfer using Google Protobuf RPC. For Protobuf, previously only know this thing, know what it does, and has been very admired, but never studied, recently just take advantage of the project opportunity, study hard.

This article focuses on configuring the Google PROTOBUF development environment under Windows with vs2012.

I. Preparatory work:

1.windows7 or other Windows systems.


2.Visual Studio 2012 or other version vs.


3.PROTOBUF: I am using the latest version of Protobuf (protobuf-2.6.1).

Under Windows, you need to download two packages:

protobuf-2.6.1.tar.bz2 (protobuf all the source code is inside, use it to compile into Lib library)

Protoc-2.6.1-win32.zip (connotation protoc.exe, the text used to compile proto files into the target language (C++,java,python), is a format defined by Google Protobuf. in fact, this file is not necessary, compile protobuf-2.6.1.tar.bz2 will generate this EXE)

Go to the official website to download Protobuf source code and compile tool: Https://developers.google.com/protocol-buffers/docs/downloads


Then unzip: my local path is D:\protobuf-2.6.1


Two. Configure the environment:


1. Enter D:\protobuf-2.6.1\vsprojects, run Protobuf.sln with vs2012, and build solution.

These people will, I will not wordy.

Then you will find that there is a lot of content in the D:\protobuf-2.6.1\vsprojects\Debug directory, the most important of which is:Libprotobuf.lib,Libprotobuf-lite.lib,Libprotoc.liband theProtoc.exe


2.d:\protobuf-2.6.1\examples would have been an example of that, we personally practice, to define a proto in this directory:

Package Tutorial;message Person {  Required String name = 1;  Required Int32 age = 2;  Optional String email = 3;}
then run Protoc.exe using CMD to generate our target language format (c + +).

CD D:\protobuf-2.6.1\vsprojects\Debug

d:\protobuf-2.6.1\vsprojects\debug>protoc-i=d:\protobuf-2.6.1\examples--cpp_out=d:\protobuf-2.6.1\ Examples D:\protobuf-2.6.1\examples\person.proto

You can then see that the person.pb.h and person.pb.cc files are generated.

3. We use vs2012 to create a new empty project, select Properties, configure:



Under Configuration Properties , click the general , Add directory to the right, and import the path D:\protobuf-2.6.1\src

Click the linker 's General , the right side of the additional library directory , import this path D:\protobuf-2.6.1\vsprojects\Debug



Three. Start one of the simplest projects

Well, everything is ready, it's time to write the code, and we'll do the simplest input and output. Create a new main.cpp, and then copy the previously generated person.pb.h and person.pb.cc into the project and add it to the project.

#include <iostream> #include "person.pb.h" using namespace Std;using namespace Tutorial;int main () {person person; Person.set_name ("Flamingo");   Person.set_age ();   Cout<<person.name () <<endl;cout<<person.age () <<endl;system ("pause"); return 0;}


Some people say it works, but my side is not, mainly


Find the reason online, and finally found that need to add two lines in the code:


#pragma comment (lib, "Libprotobuf.lib") #pragma comment (lib, "Libprotoc.lib")


will be able to run normally:



Use and principle of protobuf , please view:http://blog.csdn.net/majianfei1023/article/details/45112415

Google Protobuf Learning Note one: Under Windows environment configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.