安装Sharp /usr/include/vips/vips8:35:25: 致命错误: glib-object.h

15

我正在尝试在Ubuntu 16.04 LTS上安装sharp。

最初我没有安装vips,所以我安装了

    sudo apt-get install libvips-dev

这解决了第一个错误,但现在我遇到了另一个错误,卡在这里了:

    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

所以,我找出了glib-object.h文件所属的包并尝试安装它,但它已经被安装好了。事实上,该文件确实存在。

    /usr/include/glib-2.0/glib-object.h
在浏览了很多内容后,我发现一个类似的问题,他们问头文件的位置是否在 pkg-config --cflags vips-cpp 中。对于提问者来说不是,这导致了一个解决方案,但对于我来说位置是正确的(从底部数第二个)。
    > 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

在确认文件存在且其所在文件夹包含在上述输出中后,我并没有找到任何解决方案。下一步我毫无头绪,因此非常感激任何建议。

npm是一个最新的安装(截至昨天),如果有影响的话。


Sharp应该在Ubuntu 14.04+上包含一个libvips二进制文件,请参见http://sharp.pixelplumbing.com/en/stable/install/...你所需要的只是`npm install sharp`。我建议卸载Ubuntu的libvips,然后再从npm安装sharp。 - jcupitt
谢谢大家。最后我决定升级操作系统,问题得到了解决。没有升级之前,我无法测试其他可能修复问题的方法,但我的结论是使用了不再支持的旧库。 - Rachel
3个回答

2
你有两个问题(我想):首先,Ubuntu 16.04 自带的 nodejs 是 4.x 版本,该版本自 2018 年 4 月起不再支持,而当前受支持的 nodejs 版本是 8.x。其次,Ubuntu 16.04 自带的 libvips 也非常老旧,无法很好地与当前的 sharp 兼容。

幸运的是,修复方法很简单:使用 nodejs 6、8 和 10,sharp 将自动为您下载一个 libvips 二进制文件。

我使用了这个指南来安装 nodejs 8:

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

然后只需要:
npm install sharp

一切都正常运行。这是一个参考的Dockerfile

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


0

我曾经遇到过完全相同的问题。对我来说,我通过从官方Github编译libvips来解决了这个问题。以下是说明: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

在解决glib-object.h问题之后,你可能会遇到另一个错误:libvips-cpp.so.42: cannot open shared object file: No such file or directory。

这可以通过执行以下单个命令来解决:

sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/usrlocal.conf'

嗨 @linden-x-quan,在运行你的docker命令后,还是出现了错误。错误信息: 安装"sharp"模块时出现问题 libvips-cpp.so.42: 无法打开共享对象文件:没有那个文件或目录 - hyphens2

0

看起来vips-cpp正在寻找GObject,而不是GLib,但pkg-config文件只要求GLib。 GObject基于GLib,并且它们密切相关,但它们不是同一个项目。

您应该以某种方式将gobject-2.0添加到pkg-config依赖项中。您可以在sharp构建系统中执行此操作(无论它从哪里获取vips-cpp包,都让它依赖于gobject-2.0)。您还可以修复vips-cpp的pkg-config文件,以添加gobject-2.0作为依赖项; 文件所在位置取决于您的架构, 但它是$LIBDIR/pkg-config/vips-cpp.pc


嗨,我是libvips的维护者。vips-cpp.pc正在请求gobject:https://github.com/jcupitt/libvips/blob/master/vips-cpp.pc.in#L9,所以我认为这应该没问题。 - jcupitt
OP正在运行一个旧版本的Ubuntu;也许它有一个来自gobject-2.0之前添加的libvips版本? - nemequ
1
哦,没错,OP没有从源代码构建,他们正在使用发行版的libvips。它会很古老。我也会在docker中尝试更近期的节点。 - jcupitt
我在Ubuntu 18.04,Node 12.x中遇到了同样的问题,但通过从源代码构建libvips,我成功解决了它。 - Himanshu Chandra

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