Getting started with Google Protobuf in the Windows environment

Source: Internet
Author: User

I am using the latest version of Protobuf (protobuf-2.6.1), and the programming tools use VS2010. A brief introduction of Google Protobuf:

Google Protobuf is mainly used for communication, is a Google out of a structured information transfer tool, with high efficiency, accounting for the advantages of less storage, often used for network communication.

Google Protobuf is primarily for Linux development, but Google also provides a solution to take care of Windows developers.

Under Windows, you need to download two packages of protobuf-2.6.1.tar.bz2 and Protobuf-2.6.1-win32.zip

Download link http://code.google.com/p/protobuf/downloads/list

Next is the operation of the two packages in the Windows environment:

First, assume that two packets are placed in the G-root directory, directly unzip two packets. In the G:\protobuf-2.6.1\vsprojects under the Protobuf.sln this file, open with VS2010, get the following 9 solutions.

There may be other tutorials that say there are minor problems with the conversion here, but I didn't run into it when I did this, and it was one step.

Second, in Solution ' Protobuf ' (9 projects) that right click on Build solution generate the files we need.

Iii. after completing the previous step, the following. exe file and. lib file are generated under G:\protobuf-2.5.0\vsprojects\Debug

Now let's use these generated files.

Under G:\protobuf-2.6.1\examples, write a Person.proto file with the following code:

Package LM;

Message HelloWorld

{

Required Int32 id=1;

Required String str=2;

Optional Int32 opt=3;

}

Open DOS Command interface (run->cmd), switch directory to G:\protobuf-2.6.1\vsprojects\Debug, enter command line: PROTOC-I=G:\PROTOBUF-2.6.1\EXAMPLES--CPP_ Out=g:\protobuf-2.6.1\examples G:\protobuf-2.6.1\examples\person.proto

Pay special attention to the spaces here. The command means to have the Person.proto file generate. h and. cc files, cpp_out to generate C + + code, the first path after the cpp_out equals sign is the storage path of the generated file, and the second refers to the absolute path of the. proto file.

Create a new project, named Person_, to bring the generated person.pb.h and person.pb.cc files into the project,

It is important to note that it is not enough to import files into the project, preferably in the project directory, or else the following error may occur. copying. Pd.h and. pd.cc files to the project directory will not report such errors.

Start now to configure the path of the header and Lib files that the project uses PROTOBUF

Right-click Project, open properties (attributes)

Click C/c++general (General) under Configurationproperties (Configuration Properties), right Additionalinclude directories (additional included directories), import this path g:\ Protobuf-2.5.0\src

Enter the configuration properties again, click Linker (Linker) Àgeneral (general), the right additional librarydirectories (additional library directory), import this path G:\protobuf-2.5.0\vsprojects\ Debug

Four, next write Person.cpp

#include <iostream>
#include <string>
#include "Person.pb.h"

using namespace Std;

int main ()
{
Lm::helloworld MSG1;
MSG1.SET_ID (100);
MSG1.SET_STR ("200");
Msg1.set_opt (50);

cout << msg1.id () << Endl;
cout << msg1.str () << Endl;
cout << msg1.opt () << Endl;

Cin.get ();
return 0;
}

Drink from

http://blog.csdn.net/chenkjiang/article/details/12569835

Getting started with Google Protobuf in the Windows environment

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.