最好是弄个新安装的虚拟机来搞这个,搞这个中间出问题很多。各种花式出错。
地址:https://thrift.apache.org/download,我下载的是0.16.0版本的
创建文件夹thrfit,然后使用wget命令下载
wget https://dlcdn.apache.org/thrift/0.16.0/thrift-0.16.0.tar.gz
详情如下所示:
- lkmao@lkmao-virtual-machine:~$ mkdir thrift
- lkmao@lkmao-virtual-machine:~$ cd thrift/
- lkmao@lkmao-virtual-machine:~/thrift$ ls
- lkmao@lkmao-virtual-machine:~/thrift$ wget https://dlcdn.apache.org/thrift/0.16.0/thrift-0.16.0.tar.gz
- --2022-09-05 15:45:50-- https://dlcdn.apache.org/thrift/0.16.0/thrift-0.16.0.tar.gz
- Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
- Connecting to dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... connected.
- HTTP request sent, awaiting response... 200 OK
- Length: 4085114 (3.9M) [application/x-gzip]
- Saving to: ‘thrift-0.16.0.tar.gz’
-
- thrift-0.16.0.tar.g 100%[===================>] 3.90M 125KB/s in 14s
-
- 2022-09-05 15:46:04 (289 KB/s) - ‘thrift-0.16.0.tar.gz’ saved [4085114/4085114]
-
- lkmao@lkmao-virtual-machine:~/thrift$
解压
-
- lkmao@lkmao-virtual-machine:~/thrift$ tar zxvf thrift-0.16.0.tar.gz
- /*略*/
- lkmao@lkmao-virtual-machine:~/thrift$ ls
- thrift-0.16.0 thrift-0.16.0.tar.gz
- lkmao@lkmao-virtual-machine:~/thrift$
这小结是官方教程,按步骤操作参考下一节内容。
参考官网教程,没必要到处去百度参考官网教程即可。原文如下所示。
Building from source¶
First make sure your system meets all necessary Apache Thrift Requirements
If you are building from the first time out of the source repository, you will need to generate the configure scripts. (This is not necessary if you downloaded a released tarball.) From the top directory, do:
./bootstrap.sh
Once the configure scripts are generated, thrift can be configured. From the top directory, do:
./configure
Disable a language:
./configure --without-java
You may need to specify the location of the boost files explicitly. If you installed boost in /usr/local, you would run configure as follows:
./configure --with-boost=/usr/local
If you want to override the logic of the detection of the Java SDK, use the JAVAC environment variable:
./configure JAVAC=/usb/bin/javac
Note that by default the thrift C++ library is typically built with debugging symbols included. If you want to customize these options you should use the CXXFLAGS option in configure, as such:
./configure CXXFLAGS='-g -O2' ./configure CFLAGS='-g -O2' ./configure CPPFLAGS='-DDEBUG_MY_FEATURE'To see other configuration options run
./configure --help
Once you have run configure you can build Thrift via make:
make
and run the test suite:
make check
and the cross language test suite:
sh test/test.sh
Issues while compiling
- “compiler/cpp/thriftl.cc:2190: undefined reference to `yywrap’”
you need to install the Flex library (See also Apache Thrift Requirements ) and re-run the configuration script.
- mv: cannot stat “‘.deps/TBinaryProtocol.Tpo’: No such file or directory” while building the Thrift Runtime Library
Re-reun configure with
--enable-libtool-lock
or by turning off parallel make by placing .NOTPARALLEL: in lib/cpp/Makefile or
make -j 1
Although the thrift compiler build appears to be compatible with parallel make without libtool lock, the thrift runtime build is not.
Installing
From the top directory, become superuser and do:
make install
Note that some language packages must be installed manually using build tools better suited to those languages (this applies to Java, Ruby, PHP).
Look for the README file in the
lib/
folder for more details on the installation of each language library package./
源码编译,首先安装必备软件
sudo apt-get install automake bison flex g++ git libboost-all-dev libevent-dev libssl-dev libtool make pkg-config
安装glib2.0库,交叉编译版本需要自己下载源码编译
sudo apt-get install libglib2.0-dev
经常编译的,瞄一眼就秒懂了。
1)./bootstrap.sh
./bootstrap.sh
2) ./configure
./configure
3)make
make
4)make install
make install
./bootstrap.sh
- lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$ ./bootstrap.sh
- make distclean... ok
- aclocal.m4:17: warning: this file was generated for autoconf 2.69.
- You have another version of autoconf. It may work, but is not guaranteed to.
- If you have problems, you may need to regenerate the build system entirely.
- To do so, use the procedure documented by the package, typically 'autoreconf'.
- /*
- 略
- */
- configure.ac:578: the top level
- configure.ac:579: warning: The macro `AC_HEADER_TIME' is obsolete.
- configure.ac:579: You should run autoupdate.
- ./lib/autoconf/headers.m4:743: AC_HEADER_TIME is expanded from...
- configure.ac:579: the top level
- configure.ac:581: warning: The macro `AC_TYPE_SIGNAL' is obsolete.
- configure.ac:581: You should run autoupdate.
- ./lib/autoconf/types.m4:776: AC_TYPE_SIGNAL is expanded from...
- configure.ac:581: the top level
- lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$
有很多警告,不知道怎么处理,继续向前执行
./configure
- lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$ ./configure
- checking for a BSD-compatible install... /usr/bin/install -c
- checking whether build environment is sane... yes
- checking for a race-free mkdir -p... /usr/bin/mkdir -p
- checking for gawk... no
- checking for mawk... mawk
- checking whether make sets $(MAKE)... yes
- checking whether make supports nested variables... yes
- checking whether UID '1000' is supported by ustar format... yes
- checking whether GID '1000' is supported by ustar format... yes
- /*略*/
- thrift 0.16.0
-
- Building C (GLib) Library .... : yes
- Building C++ Library ......... : yes
- Building Common Lisp Library.. : no
- Building D Library ........... : no
- Building Dart Library ........ : no
- Building .NET Standard Library : no
- Building Erlang Library ...... : no
- Building Go Library .......... : no
- Building Haxe Library ........ : no
- Building Java Library ........ : no
- Building Lua Library ......... : no
- Building NodeJS Library ...... : no
- Building Perl Library ........ : no
- Building PHP Library ......... : no
- Building Python Library ...... : yes
- Building Py3 Library ......... : yes
- Building Ruby Library ........ : no
- Building Rust Library ........ : no
- Building Swift Library ....... : no
-
- C (glib):
- Using glib version ........ : 2.72.1
-
- C++ Library:
- C++ compiler .............. : g++ -std=c++11
- Build TZlibTransport ...... : yes
- Build TNonblockingServer .. : yes
- Build TQTcpServer (Qt5) ... : no
- C++ compiler version ...... : g++ (Ubuntu 11.2.0-19ubuntu1) 11.2.0
-
- Python Library:
- Using Python .............. : /usr/bin/python3
- Using Python version ...... : Python 3.10.4
- Using Python3 ............. : /usr/bin/python3
- Using Python3 version ..... : Python 3.10.4
-
- If something is missing that you think should be present,
- please skim the output of configure to find the missing
- component. Details are present in config.log.
- lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$
应该算是没出错吧,继续向前。
make,耐心等待,这个可能花15分钟左右。
- lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$ make
- make all-recursive
- make[1]: Entering directory '/home/lkmao/thrift/thrift-0.16.0'
- Making all in compiler/cpp
- make[2]: Entering directory '/home/lkmao/thrift/thrift-0.16.0/compiler/cpp'
- Making all in src
- make[3]: Entering directory '/home/lkmao/thrift/thrift-0.16.0/compiler/cpp/src'
- make all-am
- /*略*/
- ./compiler/cpp/thrift --gen html -r ../tutorial/tutorial.thrift
- make[3]: Leaving directory '/home/lkmao/thrift/thrift-0.16.0/tutorial'
- make[2]: Leaving directory '/home/lkmao/thrift/thrift-0.16.0/tutorial'
- make[2]: Entering directory '/home/lkmao/thrift/thrift-0.16.0'
- make[2]: Leaving directory '/home/lkmao/thrift/thrift-0.16.0'
- make[1]: Leaving directory '/home/lkmao/thrift/thrift-0.16.0
- lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$
大概是编译成功了吧,开始安装make install,需要管理员权限。
sudo make install
查看安装的库文件/usr/local/lib
- lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$ ls /usr/local/lib/libthrift* -ls
- 10244 -rwxr-xr-x 1 root root 10488584 Sep 5 16:08 /usr/local/lib/libthrift-0.16.0.so
- 25232 -rw-r--r-- 1 root root 25836116 Sep 5 16:08 /usr/local/lib/libthrift.a
- 1388 -rw-r--r-- 1 root root 1418768 Sep 5 16:08 /usr/local/lib/libthrift_c_glib.a
- 4 -rwxr-xr-x 1 root root 1053 Sep 5 16:08 /usr/local/lib/libthrift_c_glib.la
- 0 lrwxrwxrwx 1 root root 25 Sep 5 16:08 /usr/local/lib/libthrift_c_glib.so -> libthrift_c_glib.so.0.0.0
- 0 lrwxrwxrwx 1 root root 25 Sep 5 16:08 /usr/local/lib/libthrift_c_glib.so.0 -> libthrift_c_glib.so.0.0.0
- 660 -rwxr-xr-x 1 root root 672712 Sep 5 16:08 /usr/local/lib/libthrift_c_glib.so.0.0.0
- 4 -rwxr-xr-x 1 root root 986 Sep 5 16:08 /usr/local/lib/libthrift.la
- 1716 -rwxr-xr-x 1 root root 1756008 Sep 5 16:08 /usr/local/lib/libthriftnb-0.16.0.so
- 3564 -rw-r--r-- 1 root root 3645726 Sep 5 16:08 /usr/local/lib/libthriftnb.a
- 4 -rwxr-xr-x 1 root root 985 Sep 5 16:08 /usr/local/lib/libthriftnb.la
- 0 lrwxrwxrwx 1 root root 21 Sep 5 16:08 /usr/local/lib/libthriftnb.so -> libthriftnb-0.16.0.so
- 0 lrwxrwxrwx 1 root root 19 Sep 5 16:08 /usr/local/lib/libthrift.so -> libthrift-0.16.0.so
- 1612 -rwxr-xr-x 1 root root 1648400 Sep 5 16:08 /usr/local/lib/libthriftz-0.16.0.so
- 3480 -rw-r--r-- 1 root root 3561784 Sep 5 16:08 /usr/local/lib/libthriftz.a
- 4 -rwxr-xr-x 1 root root 982 Sep 5 16:08 /usr/local/lib/libthriftz.la
- 0 lrwxrwxrwx 1 root root 20 Sep 5 16:08 /usr/local/lib/libthriftz.so -> libthriftz-0.16.0.so
- lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$
查看头文件/usr/local/include
- lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$ ls /usr/local/include/thrift/
- async c_glib concurrency config.h processor protocol qt server 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 TToString.h
- lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$
在/usr/local/bin/目录下生成thrift可执行文件
- lkmao@lkmao-virtual-machine:~/thrift$ thrift -version
- Thrift version 0.16.0
- lkmao@lkmao-virtual-machine:~/thrift$
ok,安装成功。
一个软件的安装。