linux的thrift编译指南详细版(64位 + 32位)

linux的thrift编译指南详细版(64位 + 32位)


一、简介

thrift是使用IDL定义接口的支持多种开发语言的RPC框架,是apache项目之一。


二、编译

  • thrift依赖于boostlibeventopenssl
  • 64位系统编译32库需要安装gcc-multilibg++ - multilib:
sudo apt-get install gcc-multilib g++-multilib
  • 本教程使用Ubuntu 20.04和GCC 9.3.0。

1. OpenSSL

cd openssl-1.1.1k

# 编译64位库
./config --prefix=/usr/local/openssl
# 编译32位库
setarch i386 ./config -m32 --prefix=/usr/local/openssl

make
sudo make install

#测试
make test

2. libevent

cd libevent-2.1.12-stable

# 不使用OpenSSL --disable-openssl
# 使用OpenSSL CPPFLAGS="-I/usr/local/openssl/include" LDFLAGS="-L/usr/local/openssl/lib -lssl -lcrypto"

# 编译64位
./configure --disable-openssl --prefix=/usr/local/libevent 
# 编译32位
CC="gcc -m32" ./configure i386 --disable-openssl --prefix=/usr/local/libevent 

make
sudo make install

#测试
make check 

3. boost

cd boost_1_77_0

# 查看库
./bootstrap.sh --show-libraries
# 默认库
./bootstrap.sh --prefix=/usr/local/boost
# 定制库
./bootstrap.sh --without-libraries=container,context,exception,stacktrace,type_erasure,filesystem,locale,chrono,contract,fiber,graph,graph_parallel,iostreams,log,math,mpi,python,program_options,random,test,wave --without-icu --prefix=/usr/local/boost

# 编译64位
./b2 --with-system --with-serialization link=static threading=multi toolset=gcc address-model=64
# 编译32位
sed '12c      using gcc : : <cxxflags>-std=c++11 <compileflags>-m32 <linkflags>-m32;' -i project-config.jam
./b2  --with-system --with-serialization link=static threading=multi toolset=gcc architecture=x86 address-model=32

sudo ./b2 install

4. thrift

| 安装byacc、flex 和 bison

cd thrift-0.14.2

# 编译64位
./configure --disable-tests --disable-shared --disable-tutorial --with-cpp --without-python --without-java --without-lua --without-csharp --without-erlang --without-php --without-php_extension --without-haskell --without-perl --without-go --without-c_glib --enable-static --with-boost=/usr/local/boost --with-libevent=/usr/local/libevent --prefix=/usr/local/thrift CPPFLAGS="-I/usr/local/openssl/include" LDFLAGS="-L/usr/local/openssl/lib -lssl -lcrypto"
 
# 编译32位
./configure --disable-tests --disable-shared --disable-tutorial --with-cpp --without-python --without-java --without-lua --without-csharp --without-erlang --without-php --without-php_extension --without-haskell --without-perl --without-go --without-c_glib --enable-static --with-boost=/usr/local/boost --with-libevent=/usr/local/libevent --prefix=/usr/local/thrift CC="gcc -m32" CXX="g++ -m32" CPPFLAGS="-I/usr/local/openssl/include" LDFLAGS="-L/usr/local/openssl/lib -lssl -lcrypto"

make
sudo make install

三、检查

  1. 查看.a、.o、.so文件的信息
readelf -h libssl.a 
  1. openssl提示找不到动态库
# 视生成的位数选择: lib或lib64
sudo ln -s /usr/local/openssl/lib/libcrypto.so.1.1  /usr/lib/libcrypto.so.1.1
sudo ln -s /usr/local/openssl/lib/libssl.so.1.1  /usr/lib64/libssl.so.1.1
  1. thrift是可以不使用openssl的,但它的编译脚本有问题!需要手动改!不折腾!

四、总结

  • 现在的开发环境基本为64位,thrift默认编译为64位或交叉编译会相对简单,但是在64位系统编译为32位会很麻烦,因为thrift依赖于boost和libevent库,导致查阅资料和尝试编译耗时,效率不高。
  • 学习thrift的入门时间成本很高,相对来说,一次成功编译后续可以直接使用,还是能接受的。
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值