超メモ帳(Web式)@復活

小説書いたり、絵を描いたり、プログラムやったりするブログ。統失プログラマ。


SPONSORED LINK

Thriftのインストール


Cassandraをインストールして、PHPクライアントをインストールしようと思ったのだが、Thriftのインストールが必要というのでインストールした。ところがphpcassaを使えば、Thriftはインストールせずにいけた orz まぁ幾つかハマりどころがあったのでメモしておこうと思う。


環境はUbuntu 10.10。Cassandraはインストール済み。
Cassandraのインストール

必要なライブラリ


このあたりは公式wikiにある内容をそのままapt-getしてやればOK。


GettingDebianPackages - Thrift Wiki

# apt-get install libboost-dev libboost-test-dev libboost-program-options-dev libevent-dev automake libtool flex bison pkg-config g++ libssl-dev

ダウンロード、インストール


http://thrift.apache.org/download/

# cd /usr/local/src
# wget http://ftp.kddilabs.jp/infosystems/apache//thrift/0.7.0/thrift-0.7.0.tar.gz
# tar -zxvf thrift-0.7.0.tar.gz
# cd thrift-0.7.0

configureでなぜかpermission denied

# chmod 755 *
# ./configure


ハマりどころその1。

2011/9/1 追記。
thrift-0.7.0が出ていたのでビルドしようとしたら configureに実行可能フラグが立っておらず、ビルドできませんでした。どうもアーカイブか壊れている気がします。他のファイルも怪しいです。
install-shも実行可能になってませんね。以下のコマンドで修正してください。
chmod +x configure install-sh
http://ohnaka.jp/blog/2011/08/493


実に挙動が怪しいのでgithubからダウンロード。


GitHub - apache/thrift: Mirror of Apache Thrift

# tar -zxvf apache-thrift-8514755.tar.gz
# cd apache-thrift-8514755
# ./bootstrap.sh
# ./configure


ハマりどころその2。
makeするとなぜかfastbinary.cでハマる。Python関係のライブラリの様子。以下エラー文。

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c src/protocol/fastbinary.c -o
build/temp.linux-x86_64-2.6/src/protocol/fastbinary.o
src/protocol/fastbinary.c:20:20: error: Python.h: No such file or directory
src/protocol/fastbinary.c:21:23: error: cStringIO.h: No such file or directory
src/protocol/fastbinary.c:138: error: expected specifier-qualifier-list before ‘PyObject’
src/protocol/fastbinary.c:148: error: expected specifier-qualifier-list before ‘PyObject’
src/protocol/fastbinary.c:157: error: expected specifier-qualifier-list before ‘PyObject’
src/protocol/fastbinary.c:168: error: expected specifier-qualifier-list before ‘PyObject’
src/protocol/fastbinary.c:178: error: expected specifier-qualifier-list before ‘PyObject’
src/protocol/fastbinary.c:183: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
src/protocol/fastbinary.c:185: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
src/protocol/fastbinary.c: In function ‘check_ssize_t_32’:
src/protocol/fastbinary.c:190: warning: implicit declaration of function ‘PyErr_Occurred’
src/protocol/fastbinary.c:194: warning: implicit declaration of function ‘PyErr_SetString’
src/protocol/fastbinary.c:194: error: ‘PyExc_OverflowError’ undeclared (first use in this function)
src/protocol/fastbinary.c:194: error: (Each undeclared identifier is reported only once
src/protocol/fastbinary.c:194: error: for each function it appears in.)src/protocol/fastbinary.c: At top level:
src/protocol/fastbinary.c:201: error: expected ‘)’ before ‘*’ token
src/protocol/fastbinary.c:220: error: expected declaration specifiers or ‘...’ before ‘PyObject’src/protocol/fastbinary.c: In function ‘parse_set_list_args’:
src/protocol/fastbinary.c:221: warning: implicit declaration of function ‘PyTuple_Size’src/protocol/fastbinary.c:221: error: ‘typeargs’ undeclared (first use in this function)
src/protocol/fastbinary.c:222: error: ‘PyExc_TypeError’ undeclared (first use in this function)
src/protocol/fastbinary.c:226: warning: implicit declaration of function ‘PyInt_AsLong’
src/protocol/fastbinary.c:226: warning: implicit declaration of function ‘PyTuple_GET_ITEM’
src/protocol/fastbinary.c:231: error: ‘SetListTypeArgs’ has no member named ‘typeargs’
src/protocol/fastbinary.c: At top level:
src/protocol/fastbinary.c:237: error: expected declaration specifiers or ‘...’ before ‘PyObject’
src/protocol/fastbinary.c: In function ‘parse_map_args’:src/protocol/fastbinary.c:238: error: ‘typeargs’ undeclared (first use in this function)
src/protocol/fastbinary.c:239: error: ‘PyExc_TypeError’ undeclared (first use in this function)
src/protocol/fastbinary.c:253: error: ‘MapTypeArgs’ has no member named ‘ktypeargs’src/protocol/fastbinary.c:254: error: ‘MapTypeArgs’ has no member named ‘vtypeargs’
src/protocol/fastbinary.c: At top level:
src/protocol/fastbinary.c:260: error: expected declaration specifiers or ‘...’ before ‘PyObject’
src/protocol/fastbinary.c: In function ‘parse_struct_args’:
src/protocol/fastbinary.c:261: error: ‘typeargs’ undeclared (first use in this function)
src/protocol/fastbinary.c:262: error: ‘PyExc_TypeError’ undeclared (first use in this function)
src/protocol/fastbinary.c:266: error: ‘StructTypeArgs’ has no member named ‘klass’
src/protocol/fastbinary.c:267: error: ‘StructTypeArgs’ has no member named ‘spec’
src/protocol/fastbinary.c: At top level:
src/protocol/fastbinary.c:273: error: expected declaration specifiers or ‘...’ before ‘PyObject’
src/protocol/fastbinary.c: In function ‘parse_struct_item_spec’:
src/protocol/fastbinary.c:276: error: ‘spec_tuple’ undeclared (first use in this function)
src/protocol/fastbinary.c:277: error: ‘PyExc_TypeError’ undeclared (first use in this function)
src/protocol/fastbinary.c:291: error: ‘StructItemSpec’ has no member named ‘attrname’
src/protocol/fastbinary.c:292: error: ‘StructItemSpec’ has no member named ‘typeargs’
src/protocol/fastbinary.c:293: error: ‘StructItemSpec’ has no member named ‘defval’
src/protocol/fastbinary.c: At top level:
src/protocol/fastbinary.c:304: error: expected ‘)’ before ‘*’ token
src/protocol/fastbinary.c:309: error: expected ‘)’ before ‘*’ token
src/protocol/fastbinary.c:314: error: expected ‘)’ before ‘*’ token
src/protocol/fastbinary.c:319: error: expected ‘)’ before ‘*’ token
src/protocol/fastbinary.c:324: error: expected ‘)’ before ‘*’ token
src/protocol/fastbinary.c:338: error: expected ‘)’ before ‘*’ token
src/protocol/fastbinary.c:584: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
src/protocol/fastbinary.c: In function ‘free_decodebuf’:
src/protocol/fastbinary.c:613: warning: implicit declaration of function ‘Py_XDECREF’
src/protocol/fastbinary.c:613: error: ‘DecodeBuffer’ has no member named ‘stringiobuf’
src/protocol/fastbinary.c:614: error: ‘DecodeBuffer’ has no member named ‘refill_callable’
src/protocol/fastbinary.c: At top level:
src/protocol/fastbinary.c:618: error: expected declaration specifiers or ‘...’ before ‘PyObject’
src/protocol/fastbinary.c: In function ‘decode_buffer_from_obj’:
src/protocol/fastbinary.c:619: error: ‘DecodeBuffer’ has no member named ‘stringiobuf’
src/protocol/fastbinary.c:619: warning: implicit declaration of function ‘PyObject_GetAttr’
src/protocol/fastbinary.c:619: error: ‘obj’ undeclared (first use in this function)
src/protocol/fastbinary.c:619: error: ‘_intern_cstringio_buf’ undeclared (first use in this function)
src/protocol/fastbinary.c:620: error: ‘DecodeBuffer’ has no member named ‘stringiobuf’
src/protocol/fastbinary.c:624: warning: implicit declaration of function ‘PycStringIO_InputCheck’
src/protocol/fastbinary.c:624: error: ‘DecodeBuffer’ has no member named ‘stringiobuf’
src/protocol/fastbinary.c:626: error: ‘PyExc_TypeError’ undeclared (first use in this function)
src/protocol/fastbinary.c:630: error: ‘DecodeBuffer’ has no member named ‘refill_callable’
src/protocol/fastbinary.c:630: error: ‘_intern_cstringio_refill’ undeclared (first use in this function)
src/protocol/fastbinary.c:632: error: ‘DecodeBuffer’ has no member named ‘refill_callable’
src/protocol/fastbinary.c:637: warning: implicit declaration of function ‘PyCallable_Check’
src/protocol/fastbinary.c:637: error: ‘DecodeBuffer’ has no member named ‘refill_callable’
src/protocol/fastbinary.c: In function ‘readBytes’:
src/protocol/fastbinary.c:653: error: ‘PycStringIO’ undeclared (first use in this function)
src/protocol/fastbinary.c:653: error: ‘DecodeBuffer’ has no member named ‘stringiobuf’
src/protocol/fastbinary.c:660: error: ‘PyObject’ undeclared (first use in this function)
src/protocol/fastbinary.c:660: error: ‘newiobuf’ undeclared (first use in this function)
src/protocol/fastbinary.c:663: warning: implicit declaration of function ‘PyObject_CallFunction’
src/protocol/fastbinary.c:664: error: ‘DecodeBuffer’ has no member named ‘refill_callable’
src/protocol/fastbinary.c:664: error: ‘NULL’ undeclared (first use in this function)
src/protocol/fastbinary.c:670: warning: implicit declaration of function ‘Py_CLEAR’
src/protocol/fastbinary.c:670: error: ‘DecodeBuffer’ has no member named ‘stringiobuf’
src/protocol/fastbinary.c:671: error: ‘DecodeBuffer’ has no member named ‘stringiobuf’
src/protocol/fastbinary.c:673: error: ‘DecodeBuffer’ has no member named ‘stringiobuf’
src/protocol/fastbinary.c:681: error: ‘PyExc_TypeError’ undeclared (first use in this function)
src/protocol/fastbinary.c: In function ‘checkTypeByte’:
src/protocol/fastbinary.c:745: error: ‘PyExc_TypeError’ undeclared (first use in this function)
src/protocol/fastbinary.c: In function ‘skip’:
src/protocol/fastbinary.c:857: error: ‘PyExc_TypeError’ undeclared (first use in this function)
src/protocol/fastbinary.c: At top level:
src/protocol/fastbinary.c:870: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
src/protocol/fastbinary.c:874: error: expected declaration specifiers or ‘...’ before ‘PyObject’
src/protocol/fastbinary.c:874: error: expected declaration specifiers or ‘...’ before ‘PyObject’
src/protocol/fastbinary.c: In function ‘decode_struct’:
src/protocol/fastbinary.c:875: error: ‘spec_seq’ undeclared (first use in this function)
src/protocol/fastbinary.c:883: error: ‘PyObject’ undeclared (first use in this function)
src/protocol/fastbinary.c:883: error: ‘item_spec’ undeclared (first use in this function)
src/protocol/fastbinary.c:884: error: ‘fieldval’ undeclared (first use in this function)
src/protocol/fastbinary.c:884: error: ‘NULL’ undeclared (first use in this function)
src/protocol/fastbinary.c:901: error: ‘Py_None’ undeclared (first use in this function)
src/protocol/fastbinary.c:912: error: too many arguments to function ‘parse_struct_item_spec’
src/protocol/fastbinary.c:917: error: ‘PyExc_TypeError’ undeclared (first use in this function)
src/protocol/fastbinary.c:924: warning: implicit declaration of function ‘decode_val’
src/protocol/fastbinary.c:924: error: ‘StructItemSpec’ has no member named ‘typeargs’
src/protocol/fastbinary.c:929: warning: implicit declaration of function ‘PyObject_SetAttr’
src/protocol/fastbinary.c:929: error: ‘output’ undeclared (first use in this function)
src/protocol/fastbinary.c:929: error: ‘StructItemSpec’ has no member named ‘attrname’
src/protocol/fastbinary.c:930: warning: implicit declaration of function ‘Py_DECREF’
src/protocol/fastbinary.c: At top level:
src/protocol/fastbinary.c:942: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
src/protocol/fastbinary.c:1160: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
src/protocol/fastbinary.c:1195: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ThriftFastBinaryMethods’
src/protocol/fastbinary.c:1204: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘initfastbinary’
error: command 'gcc' failed with exit status 1
make[3]: *** [all-local] エラー 1
make[3]: ディレクトリ `/usr/local/src/apache-thrift-8514755/lib/py' から出ます
make[2]: *** [all-recursive] エラー 1
make[2]: ディレクトリ `/usr/local/src/apache-thrift-8514755/lib' から出ます
make[1]: *** [all-recursive] エラー 1
make[1]: ディレクトリ `/usr/local/src/apache-thrift-8514755' から出ます
make: *** [all] エラー 2


ggrと次の情報がヒット


ThriftをWindows + Pythonで使用する(簡易版) - Symfoware


lib/py/setup.pyがPython用のライブラリなので、そのなかにあるfastbinaryに関する記述をコメントアウト

include_dirs = []
if sys.platform == 'win32':
    include_dirs.append('compat/win32')
#fastbinarymod = Extension('thrift.protocol.fastbinary',
#                    sources = ['src/protocol/fastbinary.c'],
#                    include_dirs = include_dirs,
#                )

setup(name = 'thrift',
    version = '0.8.0-dev',
    description = 'Python bindings for the Apache Thrift RPC system',
    author = ['Thrift Developers'],
    author_email = ['dev@thrift.apache.org'],
    url = 'http://thrift.apache.org',
    license = 'Apache License 2.0',
    packages = [
        'thrift',
        'thrift.protocol',
        'thrift.transport',
        'thrift.server',
    ],
    package_dir = {'thrift' : 'src'},
    #ext_modules = [fastbinarymod],


該当箇所をコメントアウトした後、make && make install。

# make && make install


次のコマンドを叩いてみてバージョンが出るようなら問題なし。

# thrift -version


一応、これでthriftのインストールは完了。Cassandra-phpクライアントについては明日にでも…。

プライバシーポリシー免責事項