上文我们使用apt安装了Thrift开放框架,apt仓库中的Thrift是0.16.0版本,并不是官方最新版本。如果为了使用新的特性,我们需要自行编译最新版本。本文介绍采用从源代码编译的方式,来安装Thrift-0.19.0版本。
下载源代码包
最新版本下载:https://thrift.apache.org/download
历史版本下载:https://archive.apache.org/dist/thrift
使用如下命令下载最新版本:
1
| $ wget https://archive.apache.org/dist/thrift/0.19.0/thrift-0.19.0.tar.gz
|
下载之后解压:

安装软件依赖
1
| $ sudo apt install automake bison flex g++ libboost-all-dev libevent-dev libssl-dev libtool make cmake pkg-config
|
使用camke编译安装
参考官方安装指南:https://thrift.apache.org/docs/BuildingFromSource
编译和安装命令如下:
1 2 3 4 5 6 7
| $ cd build $ $ cmake -DCMAKE_INSTALL_PREFIX=/home/kevintian/apps/thrift -DWITH_NODEJS=OFF -DWITH_JAVASCRIPT=OFF .. $ $ make -j $ $ make install
|
cmake完成时命令输出:

安装完毕之后,我们看下目标目录 /home/kevintian/apps/thrift 的文件结构:
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
| kevintian@ubase:~/apps/thrift$ pwd /home/kevintian/apps/thrift kevintian@ubase:~/apps/thrift$ kevintian@ubase:~/apps/thrift$ tree . . ├── bin │ └── thrift ├── include │ └── thrift │ ├── async │ │ ├── TAsyncBufferProcessor.h │ │ ├── TAsyncChannel.h │ │ ├── TAsyncDispatchProcessor.h │ │ ├── TAsyncProcessor.h │ │ ├── TAsyncProtocolProcessor.h │ │ ├── TConcurrentClientSyncInfo.h │ │ ├── TEvhttpClientChannel.h │ │ └── TEvhttpServer.h │ ├── concurrency │ │ ├── Exception.h │ │ ├── FunctionRunner.h │ │ ├── Monitor.h │ │ ├── Mutex.h │ │ ├── ThreadFactory.h │ │ ├── Thread.h │ │ ├── ThreadManager.h │ │ └── TimerManager.h │ ├── config.h │ ├── numeric_cast.h │ ├── processor │ │ ├── PeekProcessor.h │ │ ├── StatsProcessor.h │ │ └── TMultiplexedProcessor.h │ ├── protocol │ │ ├── TBase64Utils.h │ │ ├── TBinaryProtocol.h │ │ ├── TBinaryProtocol.tcc │ │ ├── TCompactProtocol.h │ │ ├── TCompactProtocol.tcc │ │ ├── TDebugProtocol.h │ │ ├── TEnum.h │ │ ├── THeaderProtocol.h │ │ ├── TJSONProtocol.h │ │ ├── TList.h │ │ ├── TMap.h │ │ ├── TMultiplexedProtocol.h │ │ ├── TProtocolDecorator.h │ │ ├── TProtocolException.h │ │ ├── TProtocol.h │ │ ├── TProtocolTap.h │ │ ├── TProtocolTypes.h │ │ ├── TSet.h │ │ └── TVirtualProtocol.h │ ├── qt │ │ ├── TQIODeviceTransport.h │ │ └── TQTcpServer.h │ ├── server │ │ ├── TConnectedClient.h │ │ ├── TNonblockingServer.h │ │ ├── TServerFramework.h │ │ ├── TServer.h │ │ ├── TSimpleServer.h │ │ ├── TThreadedServer.h │ │ └── TThreadPoolServer.h │ ├── TApplicationException.h │ ├── TBase.h │ ├── TConfiguration.h │ ├── TDispatchProcessor.h │ ├── thrift-config.h │ ├── thrift_export.h │ ├── Thrift.h │ ├── TLogging.h │ ├── TNonCopyable.h │ ├── TOutput.h │ ├── TProcessor.h │ ├── transport │ │ ├── PlatformSocket.h │ │ ├── SocketCommon.h │ │ ├── TBufferTransports.h │ │ ├── TFDTransport.h │ │ ├── TFileTransport.h │ │ ├── THeaderTransport.h │ │ ├── THttpClient.h │ │ ├── THttpServer.h │ │ ├── THttpTransport.h │ │ ├── TNonblockingServerSocket.h │ │ ├── TNonblockingServerTransport.h │ │ ├── TNonblockingSSLServerSocket.h │ │ ├── TPipe.h │ │ ├── TPipeServer.h │ │ ├── TServerSocket.h │ │ ├── TServerTransport.h │ │ ├── TShortReadTransport.h │ │ ├── TSimpleFileTransport.h │ │ ├── TSocket.h │ │ ├── TSocketPool.h │ │ ├── TSocketUtils.h │ │ ├── TSSLServerSocket.h │ │ ├── TSSLSocket.h │ │ ├── TTransportException.h │ │ ├── TTransport.h │ │ ├── TTransportUtils.h │ │ ├── TVirtualTransport.h │ │ ├── TWebSocketServer.h │ │ └── TZlibTransport.h │ ├── TToString.h │ └── windows │ ├── config.h │ ├── GetTimeOfDay.h │ ├── Operators.h │ ├── OverlappedSubmissionThread.h │ ├── SocketPair.h │ ├── Sync.h │ ├── TWinsockSingleton.h │ └── WinFcntl.h └── lib ├── cmake │ └── thrift │ ├── FindLibevent.cmake │ ├── ThriftConfig.cmake │ ├── ThriftConfigVersion.cmake │ ├── thriftnbTargets.cmake │ ├── thriftnbTargets-relwithdebinfo.cmake │ ├── thriftTargets.cmake │ ├── thriftTargets-relwithdebinfo.cmake │ ├── thriftzTargets.cmake │ └── thriftzTargets-relwithdebinfo.cmake ├── libthrift.a ├── libthriftnb.a ├── libthriftz.a └── pkgconfig ├── thrift-nb.pc ├── thrift.pc └── thrift-z.pc
15 directories, 114 files kevintian@ubase:~/apps/thrift$
|
与采用apt安装的方法一致,所需可执行程序、头文件、库、pc文件等,都安装完毕。
参考官方安装指南:https://thrift.apache.org/docs/BuildingFromSource
编译和安装命令如下:
1 2 3 4 5 6 7
| $ ./bootstrap.sh $ $ ./configure --with-cpp --prefix=/home/kevintian/apps/thrift $ $ make -j $ $ make install
|
configure完成时命令输出:

安装完毕之后,我们看下目标目录 /home/kevintian/apps/thrift 的文件结构:
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| kevintian@ubase:~/apps/thrift$ kevintian@ubase:~/apps/thrift$ pwd /home/kevintian/apps/thrift kevintian@ubase:~/apps/thrift$ kevintian@ubase:~/apps/thrift$ tree . . ├── bin │ └── thrift ├── include │ └── thrift │ ├── async │ │ ├── TAsyncBufferProcessor.h │ │ ├── TAsyncChannel.h │ │ ├── TAsyncDispatchProcessor.h │ │ ├── TAsyncProcessor.h │ │ ├── TAsyncProtocolProcessor.h │ │ ├── TConcurrentClientSyncInfo.h │ │ ├── TEvhttpClientChannel.h │ │ └── TEvhttpServer.h │ ├── concurrency │ │ ├── Exception.h │ │ ├── FunctionRunner.h │ │ ├── Monitor.h │ │ ├── Mutex.h │ │ ├── ThreadFactory.h │ │ ├── Thread.h │ │ ├── ThreadManager.h │ │ └── TimerManager.h │ ├── config.h │ ├── numeric_cast.h │ ├── processor │ │ ├── PeekProcessor.h │ │ ├── StatsProcessor.h │ │ └── TMultiplexedProcessor.h │ ├── protocol │ │ ├── TBase64Utils.h │ │ ├── TBinaryProtocol.h │ │ ├── TBinaryProtocol.tcc │ │ ├── TCompactProtocol.h │ │ ├── TCompactProtocol.tcc │ │ ├── TDebugProtocol.h │ │ ├── TEnum.h │ │ ├── THeaderProtocol.h │ │ ├── TJSONProtocol.h │ │ ├── TList.h │ │ ├── TMap.h │ │ ├── TMultiplexedProtocol.h │ │ ├── TProtocolDecorator.h │ │ ├── TProtocolException.h │ │ ├── TProtocol.h │ │ ├── TProtocolTap.h │ │ ├── TProtocolTypes.h │ │ ├── TSet.h │ │ └── TVirtualProtocol.h │ ├── qt │ │ ├── TQIODeviceTransport.h │ │ └── TQTcpServer.h │ ├── server │ │ ├── TConnectedClient.h │ │ ├── TNonblockingServer.h │ │ ├── TServerFramework.h │ │ ├── TServer.h │ │ ├── TSimpleServer.h │ │ ├── TThreadedServer.h │ │ └── TThreadPoolServer.h │ ├── TApplicationException.h │ ├── TBase.h │ ├── TConfiguration.h │ ├── TDispatchProcessor.h │ ├── thrift-config.h │ ├── thrift_export.h │ ├── Thrift.h │ ├── TLogging.h │ ├── TNonCopyable.h │ ├── TOutput.h │ ├── TProcessor.h │ ├── transport │ │ ├── PlatformSocket.h │ │ ├── SocketCommon.h │ │ ├── TBufferTransports.h │ │ ├── TFDTransport.h │ │ ├── TFileTransport.h │ │ ├── THeaderTransport.h │ │ ├── THttpClient.h │ │ ├── THttpServer.h │ │ ├── THttpTransport.h │ │ ├── TNonblockingServerSocket.h │ │ ├── TNonblockingServerTransport.h │ │ ├── TNonblockingSSLServerSocket.h │ │ ├── TPipe.h │ │ ├── TPipeServer.h │ │ ├── TServerSocket.h │ │ ├── TServerTransport.h │ │ ├── TShortReadTransport.h │ │ ├── TSimpleFileTransport.h │ │ ├── TSocket.h │ │ ├── TSocketPool.h │ │ ├── TSocketUtils.h │ │ ├── TSSLServerSocket.h │ │ ├── TSSLSocket.h │ │ ├── TTransportException.h │ │ ├── TTransport.h │ │ ├── TTransportUtils.h │ │ ├── TVirtualTransport.h │ │ ├── TWebSocketServer.h │ │ └── TZlibTransport.h │ └── TToString.h └── lib ├── libthrift-0.19.0.so ├── libthrift.a ├── libthrift.la ├── libthriftnb-0.19.0.so ├── libthriftnb.a ├── libthriftnb.la ├── libthriftnb.so -> libthriftnb-0.19.0.so ├── libthrift.so -> libthrift-0.19.0.so ├── libthriftz-0.19.0.so ├── libthriftz.a ├── libthriftz.la ├── libthriftz.so -> libthriftz-0.19.0.so └── pkgconfig ├── thrift-nb.pc ├── thrift.pc └── thrift-z.pc
12 directories, 106 files kevintian@ubase:~/apps/thrift$
|
与采用apt安装的方法一致,所需可执行程序、头文件、库、pc文件等,都安装完毕。
测试
测试方法与上文方法一致,注意修改Makefile中的头文件路径和库路径即可。