静态链接vips(libvips)二进制

时间:2016-09-26 23:44:24

标签: static-libraries vips

我一直在尝试创建vips的静态链接版本,但一直无法使用。是否可以创建静态链接的vips命令?

我正在编译的平台是Ubuntu 16.04。

我正在运行的make命令:

 make LDFLAGS=-all-static

我没有将它配置为使用python或imagemagick,(在配置输出中显示" no")。我得到的错误是:

/usr/bin/ld: cannot find -lgdk_pixbuf-2.0
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libgio-2.0.a(libgio_2_0_la-glocalfileinfo.o): In function `lookup_gid_name':
(.text+0x11d7): warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libgio-2.0.a(libgio_2_0_la-glocalvfs.o): In function `g_local_vfs_parse_name':
(.text+0x1cd): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglib-2.0.a(libglib_2_0_la-gutils.o): In function `g_get_user_database_entry':
(.text+0x249): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglib-2.0.a(libglib_2_0_la-gutils.o): In function `g_get_user_database_entry':
(.text+0xcf): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libgio-2.0.a(libgio_2_0_la-glocalfileinfo.o): In function `lookup_uid_data':
(.text+0x1054): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(nanohttp.o): In function `xmlNanoHTTPConnectHost':
(.text+0x924): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(nanohttp.o): In function `xmlNanoHTTPConnectHost':
(.text+0x9f4): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libgio-2.0.a(libgio_2_0_la-gnetworkaddress.o): In function `g_network_address_parse':
(.text+0xc39): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libgio-2.0.a(libgio_2_0_la-gnetworkaddress.o): In function `g_network_address_parse':
(.text+0xc4e): warning: Using 'endservent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
Makefile:597: recipe for target 'vips' failed
make[2]: *** [vips] Error 1
make[2]: Leaving directory '/usr/local/src/vips-8.4.1/tools'
Makefile:631: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/usr/local/src/vips-8.4.1'
Makefile:536: recipe for target 'all' failed
make: *** [all] Error 2

从我发现的内容,例如: Create statically-linked binary that uses getaddrinfo? 这是libnss的一个问题。但是在./configure --help输出中没有--enable-static-flag。即便如此,我也尝试过,但它并没有解决我的问题。

我链接的库(根据配置输出,我已将其截断):

build radiance support:         yes
build analyze support:          yes
build PPM support:          yes
use fftw3 for FFT:          yes
accelerate loops with orc:      yes
ICC profile support with lcms:      yes (lcms2)
SVG import with librsvg-2.0:        yes
zlib:                   yes
file import/export with libwebp:    yes
file import/export with libpng:     yes (pkg-config libpng >= 1.2.9)
file import/export with libtiff:    yes (pkg-config libtiff-4)
file import/export with giflib:     yes (found by search)
file import/export with libjpeg:    yes
use libexif to load/save JPEG metadata: yes

我链接的特定库是否会导致问题?

2 个答案:

答案 0 :(得分:1)

我试过这样:

$ CFLAGS="-static" CXXFLAGS="-static" ./configure --prefix=/home/john/vips --without-python --without-magick

似乎有效:

$ ls ~/vips/lib
girepository-1.0  libvipsCC.a   libvips-cpp.a   libvips.la  python2.7
libvips.a         libvipsCC.la  libvips-cpp.la  pkgconfig
$ which vips
/home/john/vips/bin/vips
$ ls -l ~/vips/bin/vips
-rwxr-xr-x 1 john john 6373864 Sep 27 13:16 /home/john/vips/bin/vips
$ vips invert /data/john/pics/k2.jpg x.jpg
$ eog x.jpg

我没有经过多少测试,我怀疑它并不是非常静态的。例如,如果您在vips二进制文件上运行ldd,则会得到一个很长的列表。真正的静态二进制文件不再存在。

为什么要一个静态二进制文件?如果要简化分发,像flatpack和snappy这样的东西可能会更好。你也可以自己排序 - 例如,vips带有一个简单的包装脚本,可以使共享的二进制文件可重定位。

答案 1 :(得分:0)

在无法说服构建机制进行静态链接之后,我向{x1}报告了an issue并发现它确实是可以成功地使用vips创建了一个静态的staticx工作可执行文件固定。请参阅here了解我的建造方式。

以防万一将来地雷的连接消失,以下是相关部分:

RUN curl -sL https://github.com/libvips/libvips/releases/download/v8.9.2/vips-8.9.2.tar.gz | tar -xz -f- --strip-components=1 -C .

# TODO: Add --disable-deprecated
# Blocked by https://github.com/libvips/libvips/pull/1593

# XXX: -static doesn't work here, I'm using staticx to make the final vips binary static.
RUN CFLAGS="-O3 -flto -pipe" CXXFLAGS="-O3 -flto -pipe" \
    ./configure \
        --disable-shared \
        --disable-static \
        --disable-dependency-tracking

# This is the fastest easiest way I found to compile the
# CLI as fast as possible. You can probably get more optimal,
# but it'd be a lot harder wrestling autotools.
RUN cd libvips \
    && make -j"$(nproc)"
RUN cd tools \
    && make -j"$(nproc)" vips

RUN cd tools \
    && staticx vips ../vips

由于可自动配置功能检测,因此以下是我安装的Debian 10(6月22日)软件包:

    libglib2.0-dev \
    libexpat1-dev \
    libjpeg-dev \
    libpng-dev \
    libimagequant-dev \
    libexif-dev \
    liborc-0.4-dev

它重330万,相当令人印象深刻,比分发软件包小得多,这就是为什么我首先着手这样做的原因。

$ file vips-glibc-gcc
vips-glibc-gcc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
$ ls -lah vips-glibc-gcc
-rwxr-xr-x 1 josh josh 3.3M Jun 23 02:51 vips-glibc-gcc
相关问题