编译后的Thrift bin文件大

问题描述 投票:0回答:1

我在使用alpine 3.8的docker容器中编译Thrift时遇到问题

FROM alpine:3.8

RUN apk add --update --no-cache \
        libstdc++ \
        libgcc \
        libevent \
        composer \
        tar \
        git \
        bash \
        nginx

RUN  apk add --update --no-cache php7-dev boost-dev  autoconf  openssl-dev  automake make libtool bison flex  g++  && \
     cd /tmp && wget https://github.com/apache/thrift/archive/0.11.0.zip -O thrift.zip  && unzip thrift.zip && cd thrift-0.11.0 && \
     ./bootstrap.sh && ./configure --with-openssl=/usr/include/openssl --without-ruby --disable-tests --without-php_extension --without-python --without-haskell --without-java --without-perl --without-php --without-py3 --without-erlang && make && make install && \
     cd /tmp/thrift-0.11.0/lib/php/src/ext/thrift_protocol && phpize && ./configure && make && \
     echo 'extension=thrift_protocol.so' >> /etc/php7/conf.d/thrift_protocol.ini && \
     apk del --update --no-cache  php7-dev boost-dev  autoconf openssl-dev   automake make libtool bison flex  g++  && \
     rm -rf /tmp/*

编译后的bin文件大小约为50MB

-rwxr-xr-x    1 root     root      55566368 Sep  5 10:05 thrift

例如在Mac OSX上编译后的bin文件

 4.2M Sep  4 17:37 thrift
docker g++ thrift alpine
1个回答
0
投票

默认情况下,configure && make将导致Thrift使用调试符号构建,这是二进制膨胀的主要原因。

要构建更紧凑和优化的thrift二进制文件,请替换:

configure

附:

configure CFLAGS="-s -O2" CXXFLAGS="-s -O2"

-s编译器选项将导致调试信息从生成的对象中被剥离。 -O2编译器选项将启用常见的编译器优化,这将大大提高thrift的性能。

更多信息:

© www.soinside.com 2019 - 2024. All rights reserved.