導航:首頁 > 源碼編譯 > 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編譯相關的資料

熱點內容
明茨伯格pdf 瀏覽:440
把網頁存成pdf 瀏覽:265
如何對電腦的d盤加密 瀏覽:98
刀片式伺服器怎麼連接電腦 瀏覽:79
矩陣計算java 瀏覽:231
如何把各銀行app整合 瀏覽:877
方舟生存進化手游版如何建伺服器 瀏覽:288
哪裡購買黃金app 瀏覽:661
中國聯通app優惠購功能在哪裡 瀏覽:227
dream伺服器密碼是什麼 瀏覽:222
程序員自救 瀏覽:486
cmd殺死進程命令 瀏覽:237
ipad激活伺服器地址 瀏覽:453
單片機開始直流電機壓降問題 瀏覽:19
伺服器地址失敗怎麼辦 瀏覽:148
安卓手機怎麼下載蘇聯游戲 瀏覽:132
主教的命令 瀏覽:807
php判斷變數為空 瀏覽:745
你演我猜安卓版本怎麼用 瀏覽:910
已夠app哪裡看 瀏覽:1007