lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.26k stars 1.3k forks source link

libvips-cpp.so.42: cannot open shared object file: No such file or directory #2305

Closed joergd closed 4 years ago

joergd commented 4 years ago

I have read the page: https://sharp.pixelplumbing.com/install

I want to install sharp/vips from scratch, as I want PDF support using poppler.

I am using Docker as my machine.

Everything installs without error (it was quite a journey to get this far), and vips is configured to use various dependencies.

But when my node service starts up, and I require sharp, I get the following error:

libvips-cpp.so.42: cannot open shared object file: No such file or directory

I am installing, from source, libvips, version 8.9.2

I can see, when I configure it, that it supports jpg, webp, gif, pdf (via poppler) etc.

* build options
native win32:               no
native OS X:                no
open files in binary mode:      no
enable debug:               no
enable deprecated library components:   yes
enable docs with gtkdoc:        no
gobject introspection:          no
enable radiance support:        yes
enable analyze support:         yes
enable PPM support:             yes

* optional dependencies
use fftw3 for FFT:          no
Magick package:             none
Magick API version:             none
load with libMagick:            no
save with libMagick:            no
accelerate loops with orc:      no
  (requires orc-0.4.11 or later)
ICC profile support with lcms:      no
file import with niftiio:       no
file import with libheif:       no
file import with OpenEXR:       no
file import with OpenSlide:     no
  (requires openslide-3.3.0 or later)
file import with matio:         no
PDF import with PDFium          no
PDF import with poppler-glib:       yes
  (requires poppler-glib 0.16.0 or later)
SVG import with librsvg-2.0:        yes
  (requires librsvg-2.0 2.34.0 or later)
zlib:                   yes
file import with cfitsio:       no
file import/export with libwebp:    no
  (requires libwebp, libwebpmux, libwebpdemux 0.6.0 or later)
text rendering with pangoft2:       no
file import/export with libpng:     yes (pkg-config libpng >= 1.2.9)
  (requires libpng-1.2.9 or later)
support 8bpp PNG quantisation:      no
  (requires libimagequant)
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 (pkg-config)
image pyramid export:           no
  (requires libgsf-1 1.14.26 or later)
use libexif to load/save JPEG metadata: no

pkg-config --modversion vips-cpp
8.9.2

> ldd node_modules/sharp/build/Release/sharp.node

linux-vdso.so.1 (0x00007ffc0865e000)
libvips-cpp.so.42 => not found
libvips.so.42 => not found
libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f2b2bce9000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f2b2b9d5000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f2b2b653000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f2b2b34f000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f2b2b138000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f2b2af1b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2b2ab7c000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f2b2a973000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f2b2a700000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2b2c17c000)

I can see that the file in question does exist on my machine, but I imagine not in the location where sharp is looking.

> ls /usr/local/vips/lib

lrwxrwxrwx 1 root staff       22 Jul 23 13:11 libvips-cpp.so -> libvips-cpp.so.42.12.2
lrwxrwxrwx 1 root staff       22 Jul 23 13:11 libvips-cpp.so.42 -> libvips-cpp.so.42.12.2
-rwxr-xr-x 1 root staff  1676168 Jul 23 13:11 libvips-cpp.so.42.12.2

My Dockerfile, that I have pieced together from various sources and trial and erroring is as follows:

FROM node:14.5-slim

RUN apt-get update -qq && \
    apt-get install -qq -y --no-install-recommends \
      build-essential \
      autoconf \
      automake \
      libtool \
      intltool \
      gtk-doc-tools \
      unzip \
      wget \
      git \
      pkg-config

RUN apt-get install -qq -y --no-install-recommends \
  libglib2.0-dev \
  libexpat1-dev \
  libjpeg-dev \
  libpng-dev \
  libtiff-dev \
  libgif-dev \
  libpoppler-dev \
  libpoppler-glib-dev \
  librsvg2-dev

ENV VIPS_VERSION=8.9.2

ARG WEBP_VERSION=1.1.0

ENV VIPSHOME /usr/local/vips
ENV PKG_CONFIG_PATH $VIPSHOME/lib/pkgconfig

RUN cd /usr/src \
      && wget --no-check-certificate https://github.com/webmproject/libwebp/archive/v$WEBP_VERSION.tar.gz \
      && tar -xvf v$WEBP_VERSION.tar.gz \
      && cd libwebp-$WEBP_VERSION \
      && ./autogen.sh \
      && ./configure --prefix=$VIPSHOME --enable-libwebpmux --enable-libwebpdemux --enable-libwebpdecoder \
      && make \
      && make install \
      && ldconfig

ARG VIPS_URL=https://github.com/libvips/libvips/releases/download

RUN cd /usr/src \
      && wget --no-check-certificate ${VIPS_URL}/v${VIPS_VERSION}/vips-${VIPS_VERSION}.tar.gz \
      && tar xzf vips-${VIPS_VERSION}.tar.gz \
      && cd vips-${VIPS_VERSION} \
      && export PKG_CONFIG_PATH=/usr/src/vips/lib/pkgconfig \
      && ./configure --prefix=$VIPSHOME --disable-gtk-doc --without-magick --with-modules \
      && make \
      && make install \
      && ldconfig

RUN cd $VIPSHOME \
  && rm -rf build \
  && mkdir build \
  && tar czf \
    $VIPSHOME/build/libvips.tar.gz bin include lib

# Create and change to the app directory.
ENV INSTALL_PATH /app
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./

# # Install production dependencies.
RUN npm install --only=production --build-from-source

# Copy local code to the container image.
COPY . .

EXPOSE 8080

# Run the web service on container startup.
CMD [ "npm", "start" ]

I also get no errors when I run:

npm install --verbose sharp

My system details are as follows:

System:
  OS: Linux 4.19 Debian GNU/Linux 9 (stretch) 9 (stretch)
  CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Memory: 423.83 MB / 7.78 GB
  Container: Yes
  Shell: 4.4.12 - /bin/bash
Binaries:
  Node: 14.5.0 - /usr/local/bin/node
  Yarn: 1.22.4 - /usr/local/bin/yarn
  npm: 6.14.5 - /usr/local/bin/npm

Any help would be greatly appreciated. Compiling from source and doing all these things are not my strength, so the idea for example that sharp might be looking in the wrong folder for that libvips-cpp.so.42 is all good and well, but I have no idea to make sharp do something else .... :(

Thank you :)

lovell commented 4 years ago

If you're installing libvips to a non-standard /usr/local/vips/lib location then you'll need to ensure you tell the OS about this, either via the LD_LIBRARY_PATH environment variable, or via a config file in /etc/ld.so.conf.d.

joergd commented 4 years ago

Ok - that's a great first step out of the weeds and confusion :). Thank you.

I don't really care where it gets installed to - is there a better path, without needing to set LD_LIBRARY_PATH etc - as this would then save me from going down a whole other rabbithole of sysadmin.

joergd commented 4 years ago

Ok - so for anybody with the same issue. With @lovell's suggestion, I changed the following line in the Dockerfile.

ENV VIPSHOME /usr/local/vips

to

ENV VIPSHOME /usr/local

And now I no longer get that error, and sharp can deal with pdf's too!

lovell commented 4 years ago

Glad you got it working. If you remove --prefix=$VIPSHOME entirely then /usr/local should already be the default.

andirsun commented 2 years ago

Solution https://github.com/electron-userland/electron-builder/issues/6200#issuecomment-907830847