Linux Eclipse Run Protobuf

Source: Internet
Author: User

Installation environment Ubuntu 14.04 bit

The installation process is divided into three steps

1. Install Protobuf under Linux

2. Install the Protobuf.dt plugin under eclipse

3. Configure the dynamic link library under Eclipse and run the demo

The first step is to install Protobuf under Linux

To the official website to download PROTOBUF, the current version is 2.5.0, is also more than 1 years has not been updated

Unzip, go to the folder, run the following command in turn

./config

Make

Make check

sudo make install (This step requires administrator privileges, otherwise it will be an error)

Modifying a dynamic-link library

sudo su-execute the following command as an administrator

In vim ld.so.conf join/usr/local/lib Save exit

Executive Ldconfig

Protoc--version You can see the version number

Note here that the make install command first needs to create a folder, so administrator permissions, and secondly, the direct Su ldconfig on my machine will be error, I directly sudo su-; Finally, I installed the./config directly under the default folder (/usr/local/ LIB), so no environment variables need to be configured

The second step is to install the Protobuf.dt plugin under Eclipse

Links: https://code.google.com/p/protobuf-dt/wiki/Installing

Actually need to install two plug-ins, one is Xtext, the other is PROTOBUF-DT

Go straight to Eclipse's market and search.

I first loaded the xtext2.6, and installed the PROTOBUF-DT, the result of the installation failed, and loaded again xtext success, do not know why.

After installation, you need to do some configuration in preference, PROTOBUF is not enabled by default

Configuration can refer to link: https://code.google.com/p/protobuf-dt/wiki/IntegrationWithProtoc

After completing the second step, you can try to write the Xxx.proto file in a project clock, you will see the syntax highlighting, after saving, will automatically generate the Src-gen folder, the folder has Xxx.pb.h and xxx.pb.cc files

The third step is to configure the dynamic link library
#include"Msg.pb.h"#include<fstream>#include<iostream>using namespacestd;intMainvoid) {Lm::helloworld msg1; MSG1.SET_ID (101); Msg1.set_str ("Hello"); FStream Output ("./log"Ios:: out| Ios::trunc |ios::binary); if(!MSG1. Serializetoostream (&output)) {Cerr<<"Failed to write Msg."<<Endl; return-1; }    return 0;}

Wrote a demo,eclipse under compile failed.

But under the command line g++ msg.pb.cc writer.cpp-o Writer-lprotobuf-lpthread can be compiled successfully

Right-click Project, then click Preference, then BUiD, settting, and under setting, find GCC C + + Linker, Libraries, add two entries in Libraries (-L), Protobuf and Pthread, respectively.

The third step card me a long time, in fact, this problem in my previous use of boost when I met, the original situation is better, after all, boost with more people, and ultimately by looking for the record before doing well.

Related Article

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.