导航:首页 > 源码编译 > thrift编译

thrift编译

发布时间:2022-02-06 09:27:18

A. 为什么要用python thrift 服务端使用

这里的TestThriftService.Processor就是这里提到的Processor类,包括尖括号里面的接口TestThriftService.Iface也是由thrift编译器自动生成。

B. thrift c++ 服务端的异步怎么实现

仰望明天

thrift服务端的c++语言实现
1.thrift 概念1
thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发。它结合了功能强大的软件堆栈和代码生成引擎,以构建在 C++, java, Python, php, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, and OCaml 这些编程语言间无缝结合的、高效的服务。
thrift最初由facebook开发,07年四月开放源码,08年5月进入apache孵化器。
thrift允许你定义一个简单的定义文件中的数据类型和服务接口。以作为输入文件,编译器生成代码用来方便地生成RPC客户端和服务器通信的无缝跨编程语言。
2.生成c++语言的thrift服务端
利用thrift软件框架进行开发要首先进行环境的搭建,安装thrift运行库。
基本流程如下:
1)定义数据类型和服务接口文件:test.thrift;
2)利用代码生成引擎生成服务端框架,thrift --gen cpp test.thrift;
3)在./gen-cpp/test_server.skeleton.cpp文件中添加定制的服务;
4)编写客户端程序向服务端请求服务。
详细过程可以参加注释2给出的链接地址。
thrift定义了自己的数据类型,从而实现了跨语言平台之间的数据交换,关于thrift数据类型的详细说明可以参加注释3给出的链接地址。
3.php客户端
基于c++语言实现的thrift服务端程序经常被用在网站的后台提供实时且高效的服务,通常客户端程序是php语言的实现版本。只要根据数据类型和服务接口文件test.thrift生成php语言的接口文件即可用来调用。方法是thrift --gen php test.thrift,调用该命令后会在工作目录下生成./gen-php目录,里面有php语言的接口文件。
注释:

C. thrift可以脱离boost库吗

1. 必须安装boost。最新的稳定版是1.48.0。

1.1.先下载:sourceforge.net/projects/boost/files/boost/1.48.0/
选择tar.gz包,
下载后我解压到了/usr/local/boost_1_48下:tar zxvf boost1.48.0 -C /usr/local/boost_1_48

1.2.安装过程和以前的老版本有些不同,看自带软件包里的index.html就可以了:

主要内容涉及到安装的就2步,很简单,进入一级目录:

$ ./bootstrap.sh //默认安装到/usr/local/include/boost 和/usr/local/lib下
$ ./b2 install

1.3接下来设置环境变量自动导入:
先用vim创建文件:/etc/profile.d/boost.sh,(若不能执行的话使用chmod a+x boost.sh设置执行权限),
内容为:

#!/bin/sh
#boost settings
BOOST_ROOT=/opt/boost_1_48
BOOST_INCLUDE=/usr/local/include/boost
BOOST_LIB=/usr/local/lib
export BOOST_ROOT BOOST_INCLUDE BOOST_LIB

注意:
linux程序运行时加载共享库出现的错误:
"error while loading shared libraries: xxxx: cannot open shared object file: No such file or directory"
解决步骤:
1、使用find命令查找缺失的xxxx共享库文件所在位置。参考:#find 目录 -name "xxxx*"
2、将找到的目录位置写入 /etc/ld.so.conf 配置文件,这个文件记录了编译时使用的动态链接库的路径。
3、然后使用ldconfig命令,使配置生效。

2. 安装libevent(选择noblokingserver必须安装libevent,如果出现noblokingserver相关的错误就是没有安装libevent)。
我安装的版本是最新的libevent1.4.13:
wget http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz
tar xvzf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
./configure && make
make install
3. 接下来就是安装thrift,我下载的是最新的thrift0.8.0版本,进入thrift0.8.0目录:
因为我只需要编译cpp,用以下命令:(编译选项可以参考http://www.coder4.com/archives/2110):
./configure --with-cpp --with-boost --without-python --without-csharp --without-java --without-erlang --without-perl --without-php --without-php_extension --without-ruby --without-haskell --without-go

#make
make

#install
make install
如果还需要编译java或者别的语言,还需要提前安装别的包,具体参考http://wiki.apache.org/thrift/ThriftRequirements:
C++
Boost 1.33.1+
libevent (optional, to build the nonblocking server)
zlib (optional)
Java
Java 1.5+
Apache Ant
Apache Ivy (recommended)
Apache Commons Lang (recommended)
SLF4J
C#: Mono 1.2.4+ (and pkg-config to detect it) or Visual Studio 2005+
Python 2.4+ (including header files for extension moles)
PHP 5.0+ (optionally including header files for extension moles)
Ruby 1.8+ (including header files for extension moles)
Erlang R12 (R11 works but not recommended)
Perl 5
Bit::Vector
Class::Accessor
安装完thrift先试验一下。进入thrift下的tutorial,编译给出的例子:
thrift -r --gen cpp tutorial.thrift,

会在gen-cpp目录下生成一些文件。然后进入CPP目录,进行编译:
make
有可能遇到错误,提示: hton* declarations will not be visible to the compiler。这是thrift的一个bug,可能有的版本没有该错误,但是我安装的这个版本有。解决的办法是:
使用g++编译时加入 -DHAVE_NETINET_IN_H
这样可以使预处理器include进 netinet/in.h in thrift/protocol/TPrototol.h, 这样 hton* declarations will be visible to the compiler.
下面是一个老外对这个bug的说明:

TProtocol.h has the following lines which cause the compiler error when HAVE_NETINET_IN_H is not defined.
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif

This might be a bug in the Thrift configure script which somehow skips the define.
针对上面的那个例子,修改CPP文件夹里的Makefile,在编译行加入相应的参数:
g++ -DHAVE_NETINET_IN_H -o CppServer -I${THRIFT_DIR} -I${BOOST_DIR} -I../gen-cpp -L${LIB_DIR} -lthrift CppServer.cpp ${GEN_SRC}

再进行make,得到两个可执行文件,先执行CppServer,再启动CppClient。
到此,thrift安装完毕。

D. 什么是Thrift

E. windows使用thrift c++ 需要编译lib吗

1.从boost pro下载安装boost库,包括源文件和lib库。

2.从libevent官网下载libevent库,只有源文件。

3.从thrift官网,使用svn方式下载thrift库,只有源文件。(千万别用压缩包版本的Release发布包,里面的路径都不对)

4.在thrift库的cpp文件夹里,有libthrift和libthriftnb两个工程,这两个工程都可以直接使用VS2010打开。
其中,libthrift需要链接boost的源文件,引用boost lib库。
而libthriftnb不仅仅需要boost的源文件和boost lib库,还需要引用libevent源文件。
然后就可以编译libthrift和libthriftnb两个工程。

5.在thrift的svn的tutorial目录下,用thrift-0.8.0.exe编译tutorial.thrift和shared.thrift,会得到一堆cpp和h文件。这时,新建一个C++ Console空工程,把这些文件都引入。
期间还需要做一些小修正:
5.1 删除thrift文件里的D语言(因为没有这语言的编译器)
5.2 删除shared的skeleton.cpp(防止与Calculator的skeleton.cpp的main冲突)
5.3 为CalculatorHandler类增加一个getStruct函数实现(防止VS2010报错说不能实例化虚类,getStruct方法的内容为空,返回值和参数,直接复制SharedServiceIf.h里的)

F. thrift 编译缺少#include<transport/tsocket.h>怎么办

一个已建立的连接被你的主机上的软件终止,可能是因为一次数据传输超时或是协议错误。 WSAECONNREFUSED (10061) Connection refused. 因为目标主机主动拒绝,连接不能建立。这通常是因为试图连接到一个远程主机上不活动的服务,如没有服务器应用...

G. thrift中接口文件怎样编写

可以用来快速的开发基于Socket的接口工具。简单的说,就是可以让人快速的写Socket Server和Client。其实不用thrift开发socket也不难,那么为什么要用thrift开发呢?
主要有两个原因,一个是因为thrift本身帮你封装了很多基本的东西,你不需要自己去写socket里面的bind,accept之类的,以及他们的逻辑。可以很快速的开发基于进程的,线程的,SSL的socket。第二个理由是标准化,跨语言和跨平台,windows不算在其中。主要是在各种Posix兼容的操作系统中都可以不需要改造基本直接可用,支持的语言种类也很多,基本你会写的,他都支持。你不会写的,他也支持。
类似的项目还有ICE和Avro,但是感觉都没有thrift做的易用性好。而且这是facebook开源的诸多项目中,为数不多的能正常编译的软件。

H. nodejs怎么接入thrift

1、进入thrift.exe所在目录执行thrift-0.9.2.exe –gen js:node hello.thrift编译hello.thrift生成nodejs的实现文件。
2、在cmd窗口进入生成的gen-nodejs目录,使用npm install thrift安装nodejs的thrift模块,安装完多了一个node_moles目录。
3、新建一个js文件作为thrift的客户端。内容如下:
//引入thrift模块
var thrift = require('thrift');
//引入hello服务定义文件在同一路径下也要加 ./
var Hello = require('./Hello.js'),
ttypes = require('./hello_types');
//创建连接和客户端
var connection = thrift.createConnection('localhost', 19090),
client = thrift.createClient(Hello, connection);
//连接
connection.on('error', function(err) {
console.error(err);
});
//调用helloString函数
console.log(client.helloString('tomdog').toString());
4、启动上一篇文章中Java server程序,用node指令运行nodejsclient.js,看到控制台输出:[object Promise]。在这里js把Java返回的string当成object。

I. 如何让thrift0.9.2 在macos上面编译通过

首先,我们来参考官网的安装步骤:https://thrift.apache.org/docs/install/os_x
OS X Setup

The following command install all the required tools and libraries to build and install the Apache Thrift compiler on a OS X based system.
Install Boost

Download the boost library from boost.org untar compile with

./bootstrap.sh
sudo ./b2 threading=multi address-model=64 variant=release stage install

Install libevent

Download libevent, untar and compile with

./configure --prefix=/usr/local
make
sudo make install

Building Apache Thrift

Download the latest version of Apache Thrift, untar and compile with

./configure --prefix=/usr/local/ --with-boost=/usr/local --with-libevent=/usr/local

Additional reading

For more information on the requirements see: Apache Thrift Requirements

For more information on building and installing Thrift see: Building from source

This snippet was generated by Apache Thrift's source tree docs: doc/install/os_x.md

----------------------------------------------------------------------------------

然后,你可能会遇到下面的问题:

make[4]: *** [src/thrift/transport/TSSLSocket.lo] Error 1

openssl版本过旧导致, 在mac下面可以升级一下:

brew update
brew install openssl
brew link --force openssl

openssl version -a

processor/ProcessorTest.cpp:26:10: fatal error: 'tr1/functional' file not found

The problem here is that libc++ has been written after c++11 was "released".
You could try this:

#if __cplusplus >= 201103L
#include <functional>
#else
#include <tr1/functional>
#endif

and compile with CXXFLAGS="-std=c++11".

[thrift dir]/lib/cpp/test/processor/ProcessorTest.cpp

---------------------------------------------------------------------

library not found for -l:libboost_unit_test_framework.a thrift

为啥不能找到lib目录呢?

fuck,修改:

vim [thrift dir]/lib/cpp/test/Makefile.am

暂时用绝对路径:/usr/local/lib/ibboost_unit_test_framework.a 替换

终于通过了,跨平台为啥做的这么烂~

阅读全文

与thrift编译相关的资料

热点内容
android如何新建activity 浏览:737
ntp支持的认证算法 浏览:710
想做快手主播需要什么app 浏览:921
阿里云服务器如何转账户 浏览:901
编译器和解释器实现技术完全不同 浏览:429
虐杀原形汉化补丁怎么解压 浏览:643
文件夹验证失败 浏览:635
python是用什么软件编程 浏览:246
java并发编程教程 浏览:319
江铃宝典空调压缩机工作时间过短 浏览:634
自制单片机玩具车 浏览:901
stm32单片机模块电源电压 浏览:187
pdf层次 浏览:735
电脑里找不到编译器 浏览:843
明茨伯格pdf 浏览:442
把网页存成pdf 浏览:267
如何对电脑的d盘加密 浏览:100
刀片式服务器怎么连接电脑 浏览:82
矩阵计算java 浏览:235
如何把各银行app整合 浏览:881