• Thrift 实践1:编译安装篇


    前言

    最好是弄个新安装的虚拟机来搞这个,搞这个中间出问题很多。各种花式出错。

    一 下载源码

    地址: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

    详情如下所示:

    1. lkmao@lkmao-virtual-machine:~$ mkdir thrift
    2. lkmao@lkmao-virtual-machine:~$ cd thrift/
    3. lkmao@lkmao-virtual-machine:~/thrift$ ls
    4. lkmao@lkmao-virtual-machine:~/thrift$ wget https://dlcdn.apache.org/thrift/0.16.0/thrift-0.16.0.tar.gz
    5. --2022-09-05 15:45:50-- https://dlcdn.apache.org/thrift/0.16.0/thrift-0.16.0.tar.gz
    6. Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
    7. Connecting to dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... connected.
    8. HTTP request sent, awaiting response... 200 OK
    9. Length: 4085114 (3.9M) [application/x-gzip]
    10. Saving to: ‘thrift-0.16.0.tar.gz’
    11. thrift-0.16.0.tar.g 100%[===================>] 3.90M 125KB/s in 14s
    12. 2022-09-05 15:46:04 (289 KB/s) - ‘thrift-0.16.0.tar.gz’ saved [4085114/4085114]
    13. lkmao@lkmao-virtual-machine:~/thrift$

    解压

    1. lkmao@lkmao-virtual-machine:~/thrift$ tar zxvf thrift-0.16.0.tar.gz
    2. /*略*/
    3. lkmao@lkmao-virtual-machine:~/thrift$ ls
    4. thrift-0.16.0 thrift-0.16.0.tar.gz
    5. 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:

    1. ./configure CXXFLAGS='-g -O2'
    2. ./configure CFLAGS='-g -O2'
    3. ./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.

    三 编译源码

    1 安装依赖包

    源码编译,首先安装必备软件

    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

    2 开始编译

    经常编译的,瞄一眼就秒懂了。

    1)./bootstrap.sh

    ./bootstrap.sh

    2) ./configure

     ./configure

    3)make

    make

    4)make install    

    make install

    3 详细分析

    ./bootstrap.sh

    1. lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$ ./bootstrap.sh
    2. make distclean... ok
    3. aclocal.m4:17: warning: this file was generated for autoconf 2.69.
    4. You have another version of autoconf. It may work, but is not guaranteed to.
    5. If you have problems, you may need to regenerate the build system entirely.
    6. To do so, use the procedure documented by the package, typically 'autoreconf'.
    7. /*
    8. */
    9. configure.ac:578: the top level
    10. configure.ac:579: warning: The macro `AC_HEADER_TIME' is obsolete.
    11. configure.ac:579: You should run autoupdate.
    12. ./lib/autoconf/headers.m4:743: AC_HEADER_TIME is expanded from...
    13. configure.ac:579: the top level
    14. configure.ac:581: warning: The macro `AC_TYPE_SIGNAL' is obsolete.
    15. configure.ac:581: You should run autoupdate.
    16. ./lib/autoconf/types.m4:776: AC_TYPE_SIGNAL is expanded from...
    17. configure.ac:581: the top level
    18. lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$

    有很多警告,不知道怎么处理,继续向前执行

     ./configure
    1. lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$ ./configure
    2. checking for a BSD-compatible install... /usr/bin/install -c
    3. checking whether build environment is sane... yes
    4. checking for a race-free mkdir -p... /usr/bin/mkdir -p
    5. checking for gawk... no
    6. checking for mawk... mawk
    7. checking whether make sets $(MAKE)... yes
    8. checking whether make supports nested variables... yes
    9. checking whether UID '1000' is supported by ustar format... yes
    10. checking whether GID '1000' is supported by ustar format... yes
    11. /*略*/
    12. thrift 0.16.0
    13. Building C (GLib) Library .... : yes
    14. Building C++ Library ......... : yes
    15. Building Common Lisp Library.. : no
    16. Building D Library ........... : no
    17. Building Dart Library ........ : no
    18. Building .NET Standard Library : no
    19. Building Erlang Library ...... : no
    20. Building Go Library .......... : no
    21. Building Haxe Library ........ : no
    22. Building Java Library ........ : no
    23. Building Lua Library ......... : no
    24. Building NodeJS Library ...... : no
    25. Building Perl Library ........ : no
    26. Building PHP Library ......... : no
    27. Building Python Library ...... : yes
    28. Building Py3 Library ......... : yes
    29. Building Ruby Library ........ : no
    30. Building Rust Library ........ : no
    31. Building Swift Library ....... : no
    32. C (glib):
    33. Using glib version ........ : 2.72.1
    34. C++ Library:
    35. C++ compiler .............. : g++ -std=c++11
    36. Build TZlibTransport ...... : yes
    37. Build TNonblockingServer .. : yes
    38. Build TQTcpServer (Qt5) ... : no
    39. C++ compiler version ...... : g++ (Ubuntu 11.2.0-19ubuntu1) 11.2.0
    40. Python Library:
    41. Using Python .............. : /usr/bin/python3
    42. Using Python version ...... : Python 3.10.4
    43. Using Python3 ............. : /usr/bin/python3
    44. Using Python3 version ..... : Python 3.10.4
    45. If something is missing that you think should be present,
    46. please skim the output of configure to find the missing
    47. component. Details are present in config.log.
    48. lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$

    应该算是没出错吧,继续向前。

    make,耐心等待,这个可能花15分钟左右。

    1. lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$ make
    2. make all-recursive
    3. make[1]: Entering directory '/home/lkmao/thrift/thrift-0.16.0'
    4. Making all in compiler/cpp
    5. make[2]: Entering directory '/home/lkmao/thrift/thrift-0.16.0/compiler/cpp'
    6. Making all in src
    7. make[3]: Entering directory '/home/lkmao/thrift/thrift-0.16.0/compiler/cpp/src'
    8. make all-am
    9. /*略*/
    10. ./compiler/cpp/thrift --gen html -r ../tutorial/tutorial.thrift
    11. make[3]: Leaving directory '/home/lkmao/thrift/thrift-0.16.0/tutorial'
    12. make[2]: Leaving directory '/home/lkmao/thrift/thrift-0.16.0/tutorial'
    13. make[2]: Entering directory '/home/lkmao/thrift/thrift-0.16.0'
    14. make[2]: Leaving directory '/home/lkmao/thrift/thrift-0.16.0'
    15. make[1]: Leaving directory '/home/lkmao/thrift/thrift-0.16.0
    16. lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$

    大概是编译成功了吧,开始安装make install,需要管理员权限。

    sudo make install

    查看安装的库文件/usr/local/lib

    1. lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$ ls /usr/local/lib/libthrift* -ls
    2. 10244 -rwxr-xr-x 1 root root 10488584 Sep 5 16:08 /usr/local/lib/libthrift-0.16.0.so
    3. 25232 -rw-r--r-- 1 root root 25836116 Sep 5 16:08 /usr/local/lib/libthrift.a
    4. 1388 -rw-r--r-- 1 root root 1418768 Sep 5 16:08 /usr/local/lib/libthrift_c_glib.a
    5. 4 -rwxr-xr-x 1 root root 1053 Sep 5 16:08 /usr/local/lib/libthrift_c_glib.la
    6. 0 lrwxrwxrwx 1 root root 25 Sep 5 16:08 /usr/local/lib/libthrift_c_glib.so -> libthrift_c_glib.so.0.0.0
    7. 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
    8. 660 -rwxr-xr-x 1 root root 672712 Sep 5 16:08 /usr/local/lib/libthrift_c_glib.so.0.0.0
    9. 4 -rwxr-xr-x 1 root root 986 Sep 5 16:08 /usr/local/lib/libthrift.la
    10. 1716 -rwxr-xr-x 1 root root 1756008 Sep 5 16:08 /usr/local/lib/libthriftnb-0.16.0.so
    11. 3564 -rw-r--r-- 1 root root 3645726 Sep 5 16:08 /usr/local/lib/libthriftnb.a
    12. 4 -rwxr-xr-x 1 root root 985 Sep 5 16:08 /usr/local/lib/libthriftnb.la
    13. 0 lrwxrwxrwx 1 root root 21 Sep 5 16:08 /usr/local/lib/libthriftnb.so -> libthriftnb-0.16.0.so
    14. 0 lrwxrwxrwx 1 root root 19 Sep 5 16:08 /usr/local/lib/libthrift.so -> libthrift-0.16.0.so
    15. 1612 -rwxr-xr-x 1 root root 1648400 Sep 5 16:08 /usr/local/lib/libthriftz-0.16.0.so
    16. 3480 -rw-r--r-- 1 root root 3561784 Sep 5 16:08 /usr/local/lib/libthriftz.a
    17. 4 -rwxr-xr-x 1 root root 982 Sep 5 16:08 /usr/local/lib/libthriftz.la
    18. 0 lrwxrwxrwx 1 root root 20 Sep 5 16:08 /usr/local/lib/libthriftz.so -> libthriftz-0.16.0.so
    19. lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$

    查看头文件/usr/local/include

    1. lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$ ls /usr/local/include/thrift/
    2. 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
    3. lkmao@lkmao-virtual-machine:~/thrift/thrift-0.16.0$

    在/usr/local/bin/目录下生成thrift可执行文件

    运行验证        

    1. lkmao@lkmao-virtual-machine:~/thrift$ thrift -version
    2. Thrift version 0.16.0
    3. lkmao@lkmao-virtual-machine:~/thrift$

    ok,安装成功。

    总结

            一个软件的安装。

  • 相关阅读:
    C++ 流(stream)总结
    (四)Vue之数据绑定
    多维时序 | MATLAB实现GWO-GRU灰狼算法优化门控循环单元的多变量时间序列预测
    excel函数公式
    网络安全(黑客)自学
    30天Python入门(第十八天:深入了解Python中的正则表达式)
    SpringBoot实战案例:图书管理系统
    Idea Module “xx“ must not contain source root “xxx“ 的解决
    【QT】Ubuntu 编译安装 QT 5.12.7 源码
    【机器学习技巧】之特征工程:数字编码以及One-hot独热编码的几种方式(sklearn与pandas处理方式)
  • 原文地址:https://blog.csdn.net/yueni_zhao/article/details/126702825