Ubuntu under installation using thrift

Source: Internet
Author: User
Tags htons


1. Introduction

Thrift is an open source project for Facebook, primarily a cross-language service development framework. It has a code generator that automatically generates a service code framework for the IDL definition file it defines. As long as the user two times before the development of the line, for the underlying RPC communication, etc. are transparent. Currently it supports languages such as C + +, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C #, Cocoa, Smalltalk, and OCaml.

Environment:
Os:ubuntu 12.04.1 LTS
Kernel: 3.2.0-33-generic-pae


2. Download Thrift

1 wget http://labs. renren.com/apache-mirror//thrift/0.9.0/thrift-0.9.0. Tar. GZ (Download version 0.9.0)

3. Install dependent packages

1 sudo apt-get install Libboost-dev libboost-test-dev libboost-program-options-dev libevent-dev automake Libtool Flex Bison pkg-config g++ Libssl-dev Ant

4. Decompression

1 TAR-ZXVF thrift-*. Tar. gz

Go to catalog CD thrift-*

5. Install and compile

1 2 3 . /configure make sudo make install

6. Installation Test
After installation thrift-version View the version information, indicating that the installation was successful.
Thrift version 0.9.0


7. Self-brought example test

There are examples of thrift in the Tutorial directory where we test the CPP example.

Enter the Tutorial directory, Shared.thrift and Tutorial.thrift are interface definition files.

Executing the thirft-r--gen CPP Tutorial.thrift, you can generate the Gen-cpp directory, which is the code generated automatically by the thrift compiler.

Then go to the Tutorial/cpp directory, execute make, and generate the executable file. However, there will be a variety of errors after make, we have to correct each.


8. Errors and corrections that may occur after make

(1) Error 1: Very many errors, finding the first error is

The main idea is the/usr/local/include/thrift/concurrency/thread.h in the pthread_self, pthread_equal and so on no declaration, searched a bit as if very few people have encountered this problem. But matter, the wrong meaning can be understood, search pthread_self, pthread_equal corresponding header file is # include <pthread.h>, add to that Thread.h in good.


(2) Error 2:/USR/LOCAL/INCLUDE/THRIFT/PROTOCOL/TBINARYPROTOCOL.TCC:147:35: Error: ' htons ' argument does not depend on template parameter,

Resolution: The ' htons ' declaration must be available [-fpermissive], then modify the makefile, plus the compile option-dhave_netinet_in_h

Modified Makefile (partial)

1 2 3 4 Server:CppServer.cpp g++-dhave_netinet_in_h-o Cppserver-i${thrift_dir}-i${boost_dir}-I.. /gen-cpp-l${lib_dir}-lthrift CppServer.cpp ${gen_src} client:CppClient.cpp g++-dhave_netinet_in_h-o cppclient-i${th Rift_dir}-i${boost_dir}-I.. /gen-cpp-l${lib_dir}-lthrift CppClient.cpp ${gen_src}


(3) Error 3: Still a lot of errors

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 g++ -dhave_netinet_in_h -o cppserver -i/usr/local/include/thrift -i/usr/local/boost/ include/boost-1_33_1/  -I.. /gen-cpp -l/usr/local/lib -lthrift cppserver.cpp&nbsp ... /gen-cpp/sharedservice. cpp  /gen-cpp/shared_types. cpp  /gen-cpp/tutorial_types. cpp  /gen-cpp/calculator. CPP/TMP/CC3GKFHW .o: in  function  ' main ': CppServer.cpp: (. text+0xd1):  undefined reference to  ' apache::thrift::transport::tserversocket::tserversocket (int) ' CppServer.cpp: (. text+0x15f): undefined reference to  ' Apache::thrift::server::tsimpleserver :: Serve () '/tmp/cc3gkfhw .o: in  function  ' Apache::thrift::server::tsimpleserver::~tsimpleserver () ': CppServer.cpp: (. Text._zn6apache6thrift6server13tsimpleserverd2ev[_zn6apache6thrift6server13tsimpleserverd5ev ]+0XB): undefined reference to  ' vtable  for  apache::thrift::server:: Tsimpleserver '/tMP/CC3GKFHW .o: in  function  ' Apache::thrift::transport::tbufferedtransport::tbufferedtransport ( boost::shared_ptr<apache::thrift::transport::ttransport>) ': CppServer.cpp: (. text._ Zn6apache6thrift9transport18tbufferedtransportc2en5boost10shared_ptrins1_10ttransporteee[_ zn6apache6thrift9transport18tbufferedtransportc5en5boost10shared_ptrins1_10ttransporteee]+0x17):  undefined reference to  ' vtable  for  apache::thrift::transport::tbufferedtransport '/tmp /CC3GKFHW .o: in  function  ' Apache::thrift::server::tsimpleserver::tsimpleserver<apache:: Thrift::tprocessor> (boost::shared_ptr<apache::thrift::tprocessor> const&, boost::shared _ptr<apache::thrift::transport::tservertransport> const&, boost::shared_ptr<apache:: Thrift::transport::ttransportfactory> const&, boost::shared_ptr<apache::thrift::p rotocol:: tprotocolfactory> const&, boost::enable_if&Lt;boost::is_convertible<apache::thrift::tprocessor*, apache::thrift::tprocessor*>:: Type,  void *>:: Type) ': CppServer.cpp: (. text._zn6apache6thrift6server13tsimpleserverc2ins0_ 10tprocessoreeerkn5boost10shared_ptrit_eerkns6_ins0_9transport16tservertransporteeerkns6_insb_ 17ttransportfactoryeeerkns6_ins0_8protocol16tprotocolfactoryeeens5_9enable_ifins5_14is_convertibleips7_ps4_ E4typeepve4typee[_zn6apache6thrift6server13tsimpleserverc5ins0_10tprocessoreeerkn5boost10shared_ptrit_eerkns6_ ins0_9transport16tservertransporteeerkns6_insb_17ttransportfactoryeeerkns6_ins0_ 8PROTOCOL16TPROTOCOLFACTORYEEENS5_9ENABLE_IFINS5_14IS_CONVERTIBLEIPS7_PS4_E4TYPEEPVE4TYPEE]+0X3A):  undefined reference to  ' vtable  for  apache::thrift::server::tsimpleserver '/tmp/ CcBCSkj6 .o: in  function  ' shared::sharedserviceclient::recv_getstruct (shared::sharedstruct&) ': SharedService.cpp: (. text+0x6f3): undefined reference to  ' apache::thRift::tapplicationexception:: Read (apache::thrift::p rotocol::tprotocol*) '/tmp/ccbcskj6 .o: in  function   ' Shared::sharedserviceprocessor::p rocess (boost::shared_ptr<apache::thrift::p rotocol::tprotocol>,  boost::shared_ptr<apache::thrift::p rotocol::tprotocol>, void*) ': SharedService.cpp: (. text+ 0XB05): undefined reference to  ' Apache::thrift::tapplicationexception::write (Apache:: Thrift::p rotocol::tprotocol*)  const '/tmp/ccbcskj6 .o: in  function  ' shared:: Sharedserviceprocessor::p rocess_fn (apache::thrift::p rotocol::tprotocol*, apache::thrift::p rotocol:: Tprotocol*, std::basic_string<char, std::char_traits<char>, std::allocator<char>  >&, int, void*) ': SharedService.cpp: (. text+0xd87):  undefined reference to   ' Apache::thrift::tapplicationexception::write (apache::thrift::p rotocol::tprotocol*)  const '/tmp/ CcBCSkj6 .o: in  Function  ' shared::sharedserviceprocessor::p rocess_getstruct (int, apache::thrift::p rotocol::tprotocol*,  apache::thrift::p rotocol::tprotocol*, void*) ': SharedService.cpp: (. text+0x1409):  undefined  reference to  ' Apache::thrift::tapplicationexception::write (apache::thrift::p rotocol::tprotocol *)  const '/tmp/ccdemogv .o: in  function  ' tutorial::calculatorclient::recv_ping () ': Calculator.cpp: (. text+0x12af): undefined reference to  ' Apache::thrift:: Tapplicationexception:: Read (apache::thrift::p rotocol::tprotocol*) '/TMP/CCDEMOGV .o: in  function  ' Tutorial::calculatorclient::recv_add () ': Calculator.cpp: (. text+0x173b):  undefined reference to   ' apache::thrift::tapplicationexception:: Read (apache::thrift::p rotocol::tprotocol*) '/TMP/CCDEMOGV. O:  In  function  ' tutorial::calculatorclient::recv_calculate () ': Calculator.cpp: (. text+0x1c7b):  undefined reference to  ' Apache::thrift::tapplicationexception:: Read (apache::thrift::p rotocol::tprotocol*) '/TMP/CCDEMOGV .o:  in  function  ' tutorial::calculatorprocessor::p rocess (boost::shared_ptr<apache::thrift::p rotocol:: Tprotocol>, boost::shared_ptr<apache::thrift::p rotocol::tprotocol>, void*) ': Calculator.cpp :(. text+0x227f): undefined reference to  ' Apache::thrift::tapplicationexception::write ( Apache::thrift::p rotocol::tprotocol*)  const

Solution: Put the-lthrift in the back.

Modified Makefile

1 2 3 4 5 6 7 8 9 10 11 Boost_dir =/usr/local/boost/include/boost-1_33_1/thrift_dir =/usr/local/include/thrift LIB_DIR =/usr/local/lib GEN_ SRC =.. /gen-cpp/sharedservice. cpp. /gen-cpp/shared_types. cpp. /gen-cpp/tutorial_types. cpp. /gen-cpp/calculator. cpp default:server client server:CppServer.cpp g++-dhave_netinet_in_h-o cppserver-i${thr Ift_dir}-i${boost_dir}-I.. /gen-cpp-l${lib_dir} CppServer.cpp ${gen_src}-lthrift client:CppClient.cpp g++-dhave_netinet_in_h-o Cppclien T-i${thrift_dir}-i${boost_dir}-I.. /gen-cpp-l${lib_dir} CppClient.cpp ${gen_src}-lthrift Clean: $ (RM)-R cppclient Cppserver


9. Operation

Execute make again, run successfully, get executable program Cppserver and Cppclient

Run in two windows in turn./cppserver and./cppclient

The output is as follows:

1 2 3 4 5 6 $ . /cppclient Ping () 1+1=2 invalidoperation:cannot divide by 0 15-10=5 Check Log:5


1 2 3 4 5 6 7 $ . /cppserver starting the server ... ping () Add (All) calculate (1,{4,1,0}) calculate (1,{2,15,10}) getstruct (1)

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.