Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Sharp /usr/include/vips/vips8:35:25: fatal error: glib-object.h

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.

like image 639
Rachel Avatar asked Oct 27 '18 13:10

Rachel


1 Answers

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

like image 88
jcupitt Avatar answered Oct 15 '22 21:10

jcupitt