14

I am trying to install sharp on Ubuntu 16.04 LTS.

I originally did not have vips, so I installed

    sudo apt-get install libvips-dev

That fixed the first error, but now I get another error that I am stuck on:

    In file included from ../src/common.cc:25:0: 
    /usr/include/vips/vips8:35:25: fatal error: glib-object.h: No such file or directory
    compilation terminated.
    sharp.target.mk:115: recipe for target 'Release/obj.target/sharp/src/common.o' failed
    make: *** [Release/obj.target/sharp/src/common.o] Error 1
    make: Leaving directory '/home/rachel/node_modules/sharp/build'
    gyp ERR! build error
    gyp ERR! stack Error: `make` failed with exit code: 2
    gyp ERR! stack   at ChildProcess.onExit (/usr/share/node-gyp/lib/build.js:269:23)
    gyp ERR! stack     at emitTwo (events.js:87:13)
    gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
    gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
    gyp ERR! System Linux 4.15.0-36-generic
    gyp ERR! command "/usr/bin/nodejs" "/usr/bin/node-gyp" "rebuild"
    gyp ERR! cwd /home/rachel/node_modules/sharp
    gyp ERR! node -v v4.2.6
    gyp ERR! node-gyp -v v3.0.3
    gyp ERR! not ok

So, I figured out what package glib-object.h belongs to and tried to install it, but it was already installed. In fact, the file does exist.

    /usr/include/glib-2.0/glib-object.h

After a lot of browsing, I found a similar question where they asked if the location of the header was in pkg-config --cflags vips-cpp. For the asker it wasn't, and that lead to a fix, but for me, it is (second from the bottom).

    > pkg-config --cflags vips-cpp
    -pthread -fopenmp -DMAGICKCORE_HDRI_ENABLE=0
    -DMAGICKCORE_QUANTUM_DEPTH=16
    -fopenmp -DMAGICKCORE_HDRI_ENABLE=0
    -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/include/libgsf-1
    -I/usr/include/libxml2
    -I/usr/include/x86_64-linux-gnu//ImageMagick-6
    -I/usr/include/ImageMagick-6
    -I/usr/include/x86_64-linux-gnu//ImageMagick-6
    -I/usr/include/ImageMagick-6
    -I/usr/include/orc-0.4
    -I/usr/include/OpenEXR
    -I/usr/include/openslide
    -I/usr/lib/x86_64-linux-gnu/hdf5/serial/include
    -I/usr/include/pango-1.0
    -I/usr/include/harfbuzz
    -I/usr/include/pango-1.0
    -I/usr/include/freetype2
    -I/usr/include/x86_64-linux-gnu
    -I/usr/include/libpng12
    -I/usr/include/libexif
    -I/usr/include/glib-2.0
    -I/usr/lib/x86_64-linux-gnu/glib-2.0/include

I haven't found any solutions once verifying that the file exists and its folder is included in the above output. I have absolutely no idea what to do next, so any advice would be greatly appreciated.

npm is a fresh install (as of yesterday), in case that matters.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Rachel
  • 141
  • 1
  • 1
  • 4
  • Sharp should include a libvips binary on Ubuntu 14.04+, see http://sharp.pixelplumbing.com/en/stable/install/ ... all you need is `npm install sharp`. I would uninstall the Ubuntu libvips and try installing sharp again from npm. – jcupitt Oct 27 '18 at 18:43
  • Thanks everyone. I ended up deciding to just upgrade my os, which fixed everything. I can't test to see what would have worked to fix it without the upgrade, but the conclusion I came to was that it was using old libraries that weren't supported. – Rachel Oct 31 '18 at 18:33

3 Answers3

2

You have two problems (I think): first, the nodejs that comes with Ubuntu 16.04 is 4.x, and that became unsupported back in April 2018 -- current supported nodejs is 8.x. Secondly, the libvips that comes with Ubuntu 16.04 is also ancient and does not work well with current sharp.

Fortunately, the fix is simple: with nodejs 6, 8 and 10, sharp will automatically download a libvips binary for you.

I used this guide to install nodejs 8:

https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04#how-to-install-using-a-ppa

Then just:

npm install sharp

And everything worked. Here it is as a Dockerfile, for reference:

https://github.com/jcupitt/docker-builds/blob/master/sharp-ubuntu16.04/Dockerfile

jcupitt
  • 10,213
  • 2
  • 23
  • 39
0

It looks like vips-cpp is looking for GObject, not GLib, but the pkg-config file only asks for GLib. GObject is based on GLib, and they're closely related, but they are not the same project.

You should add gobject-2.0 to the pkg-config dependencies somehow. You can do this in the sharp build system (wherever it is pulling in the vips-cpp package, have it also depend on gobject-2.0). You could also fix your vips-cpp pkg-config file to add gobject-2.0 as a dependency; where the file is depends on your architecture, but it's $LIBDIR/pkg-config/vips-cpp.pc.

nemequ
  • 16,623
  • 1
  • 43
  • 62
  • Hi, I'm the libvips maintainer. vips-cpp.pc is asking for gobject: https://github.com/jcupitt/libvips/blob/master/vips-cpp.pc.in#L9 so I think that should be OK. – jcupitt Oct 29 '18 at 07:41
  • OP is running an old version of Ubuntu; perhaps it has a version of libvips from [before gobject-2.0 was added](https://github.com/jcupitt/libvips/blame/d5f101431b7ff83ab0c64ab23c20753e2eeba087/vips-cpp.pc.in)? – nemequ Oct 29 '18 at 14:09
  • 1
    Oh true, OP has not built from source, they are using the distro libvips. It'll be ancient. I'll have a go in docker with a more recent node as well. – jcupitt Oct 29 '18 at 14:30
  • I was having the same issue in ubuntu 18.04, node 12.x, but was able to fix it by building libvips from the source. – Himanshu Chandra May 22 '21 at 10:35
0

I had exact same issue. And For me, I solved by compiling libvips from official github. Here is instructions: https://libvips.github.io/libvips/install.html

 git clone git://github.com/jcupitt/libvips.git
 cd libvips/
 # install dependencies if you have errors during autogen.sh 
 #sudo apt install gtk-doc-tools
 #sudo apt install gobject-introspection
 ./autogen.sh
 make
 sudo make install

After solving glib-object.h issue, you may encounter another Error: libvips-cpp.so.42: cannot open shared object file: No such file or directory

This can be resolved by following single command:

sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/usrlocal.conf'
Linden X. Quan
  • 584
  • 5
  • 18
  • Hi @linden-x-quan after run your command on docker. It still error ```Error: Something went wrong installing the "sharp" module libvips-cpp.so.42: cannot open shared object file: No such file or directory``` – hyphens2 Aug 25 '23 at 03:16