静态链接的vips(libvips)二进制文件

4

我一直在试图创建一个静态链接版本的vips,但一直未能成功。是否可以创建一个静态链接的vips命令?

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

我运行的make命令如下:

 make LDFLAGS=-all-static

我没有配置它使用python或imagemagick,(在配置输出中显示为“否”)。我遇到的错误是:

/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

根据我在这里找到的信息,例如:创建使用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个回答

2
在无法说服构建机制进行静态链接后,我报告了 问题 给 staticx 并看到它被解决后,我成功地使用 staticx 创建了一个可工作的静态 vips 可执行文件。查看 此处 以了解我是如何构建的。
以防我的链接在未来失效,这里是相关部分:
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

由于configure自动进行特征检测,因此这是我安装的Debian 10(6月22日)软件包:
    libglib2.0-dev \
    libexpat1-dev \
    libjpeg-dev \
    libpng-dev \
    libimagequant-dev \
    libexif-dev \
    liborc-0.4-dev

它重3.3兆,相当令人印象深刻,比分发包要小得多,这也是我最初开始做这件事的原因。
$ 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

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带有一个简单的包装器脚本,可以使共享二进制文件可重定位。

我希望将它部署在一个极简的Docker容器中,该容器还具有静态版本的ffmpeg和ffprobe。我想我只是不确定为什么图像转换程序需要像getservbyname这样的调用,所以希望有一些依赖项可以删除。 - SjB
vips使用glib来帮助可移植性,而glib有很多东西。您可以尝试制作自己的glib并删除一些内容,这可能会有所帮助。我认为静态二进制文件^^^^将在任何16.04安装中工作,这是一件好事,但它可能无法在非常精简的Linux安装上工作。OpenWRT有一个libvips软件包,非常精简,也许您可以适应它? - jcupitt
我认为使用类似于dietlibc这样的东西可能会有效,但是我还没有机会重新审视它。 - SjB

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接