Thrift Installation Problems and tutorial instance running

Source: Internet
Author: User
Tags htons

Thrift Installation Problems and tutorial instance running _ running ostrich _ Sina Blog

Thrift Installation Problems and tutorial instance running
(14:49:26)
Reprinted token
Tags:
Thrift
Boost
Category: Open-Source Software
The thrift instance depends on boost. First, install boost.
1. Install boost
1. Download The boostinstaller package from the URL: http://sourceforge.net/projects/boost/files/boost/1.50 #/
Decompress the package to/usr/local/: tar-zxvf boost_1_50_0.tar.gz
. The installation process involves the following steps: Enter the level-1 directory/usr/local/boost_000050_0:
$./Bootstrap. Sh // installed under/usr/local/include/Boost and/usr/local/lib by default
$./B2 install
1.3 set the automatic import of environment variables:
Use VI to create a file:/etc/profile. d/Boost. Sh. (If the file cannot be executed, use chmod A + x boost. Sh to set the execution permission ),
Content:
#! /Bin/sh
# Boost settings
Boost_root =/usr/local/boost_1_50_0
Boost_include =/usr/local/include/Boost
Boost_lib =/usr/local/lib
Export boost_root boost_include boost_lib
2. Thrift test instance
Try thrift after installation.
2.1 C ++ instance
Go to the tutorial under thrift and compile the example:
Thrift-r -- Gen CPP tutorial. Thrift
Some files are generated in the Gen-CPP directory. Then go to the CPP directory and modify the MAKEFILE file as follows:
Boost_dir =/usr/local/include/Boost
Thrift_dir =/usr/local/include/Thrift
Lib_dir =/usr/local/lib
Compile:
Make
Go to the CPP directory and execute the make command. If the compilation fails, the first error is
/Usr/local/include/thrift/protocol/tbinaryprotocol. TCC: 147: 35: Error: there are no arguments to 'htons' that depend on a template parameter, so
Declaration of 'htons' must be available
Modify the makefile and add the compilation option-dhave_netinet_in_h.
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}
Run make to get two executable files, cppserver and cppclient.
Run cppserver and cppclient on two different terminals, start the server first, and then start the client.
The following error may occur during startup: Error while loading shared libraries. solution:
In general, there are many so files in the/usr/local/lib directory, so in/etc/lD. so. add the/usr/local/lib line to the conf file to solve this problem.
After you archive/etc/lD. So. conf, Run "/sbin/ldconfig-V" to update the file to make the update take effect.

2.2 Java instance
Thrift-r -- Gen Java tutorial. Thrift
Some files will be generated under the Gen-Java directory, and then enter the Java directory, execute the ant (ANT needs to be installed, and refer to ant installation) command, the following error will be prompted:
Build failed
/Opt/thrift-0.8.0/tutorial/Java/build. xml: 47:/opt/thrift-0.8.0/lib/Java/build
Does not exist.
Solution: Compile the thrift Java package when using Java.
CD thrift-0.8.0/lib/Java
Ant
After compilation is complete, a libthrift-0.8.0.jar will appear under the current directory
Copy the libthrift-0.8.0.jar to/usr/local/lib (this location is because
Java sample code build. xml indicates that the JAR file must be located in/usr/local/lib.
).
Then add/usr/local/lib/libthrift-0.8.0.jar to classpath.
Go to the Java directory again (/opt/thrift-0.8.0/tutorial/Java) and run the ant command to obtain two executable files: cppserver and cppclient.
Run javacppserver and javaclient on two different terminals. Start the server first and then start the client.
The parameters required for client execution are as follows:./javaclient secure or./javaclient simple

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.