Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debian Wheezy: sharp breaks if the canvas module is loaded first #371

Closed
papandreou opened this issue Mar 2, 2016 · 13 comments
Closed

Debian Wheezy: sharp breaks if the canvas module is loaded first #371

papandreou opened this issue Mar 2, 2016 · 13 comments
Labels

Comments

@papandreou
Copy link
Contributor

I ran into this very puzzling issue on Debian Wheezy, which I haven't been able to repro on my workstation, which runs a much newer Ubuntu.

It goes something like this:

$ nvm use 4
Now using node v4.3.1 (npm v2.14.12)
$ npm install canvas@1.3.12 sharp@0.13.1
[...]
$ node -e "require('canvas');require('sharp');"

module.js:356
  Module._extensions[extension](this, filename);
                               ^
Error: /path/to/node_modules/sharp/build/Release/../../lib/libgio-2.0.so.0: undefined symbol: g_option_group_unref
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/path/to/node_modules/sharp/index.js:12:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at [eval]:1:19
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:565:25)
    at startup (node.js:80:7)

Interestingly it does not blow up if the two requires are reversed!

It's reproducible with both node.js 0.10.38 and 4.3.1. Haven't tried any others.

Any ideas?

@lovell
Copy link
Owner

lovell commented Mar 2, 2016

I suspect canvas uses a system-wide install of libcairo2-dev, which depends on glib v2.32.4. By introducing this shared library dependency at run-time first, you supersede sharp's pre-packaged glib v2.47.5.

In this case, it's probably best to follow suit and use a system-wide install of libvips.

@lovell lovell added the question label Mar 2, 2016
@nsmag
Copy link

nsmag commented Mar 3, 2016

I got this issue too on Ubuntu 14.04.

Error: /.../node_modules/sharp/build/Release/../../lib/libgio-2.0.so.0: undefined symbol: g_option_group_unref

Sharp ran fine before I installed the canvas.

@lovell
Copy link
Owner

lovell commented Mar 3, 2016

Quick thought: are either of you able to try using the fully-versioned path to the shared library (rather than the partial-versioned symlink) in the libraries section of binding.gyp, something like:

- '<(module_root_dir)/lib/libglib-2.0.so',
+ '<(module_root_dir)/lib/libglib-2.0.so.0.4705.0',
- '<(module_root_dir)/lib/libgio-2.0.so',
+ '<(module_root_dir)/lib/libgio-2.0.so.0.4705.0',

Failing this, the only option I can think of is to experiment with the --default-symver linker flag when building the pre-compiled shared libraries to insert the version number into the symbol table.

@lovell lovell added triage and removed question labels Mar 3, 2016
@lovell
Copy link
Owner

lovell commented Mar 3, 2016

Another even quicker thought:

LD_PRELOAD=/path/to/node_modules/sharp/lib/libglib-2.0.so node script.js

...should make sharp's bundled glib take precedence regardless of module import order.

@papandreou
Copy link
Contributor Author

Sorry for not reporting back earlier. I just switched around the requires, then moved on :)

$ LD_PRELOAD=node_modules/sharp/lib/libglib-2.0.so node -e "require('canvas');require('sharp')"

(sharp:61468): GLib-GObject-CRITICAL **: /tmp/buildd/glib2.0-2.33.12+really2.32.4/./gobject/gtype.c:2722: You forgot to call g_type_init()

(sharp:61468): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed

(sharp:61468): GLib-GObject-CRITICAL **: /tmp/buildd/glib2.0-2.33.12+really2.32.4/./gobject/gtype.c:2722: You forgot to call g_type_init()

(sharp:61468): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed

... and then it hangs.

If I make the suggested patch to binding.gyp inside node_modules/sharp, then run npm install inside node_modules/sharp, I get the original error:

$ node -e "require('canvas');require('sharp')"

module.js:356
  Module._extensions[extension](this, filename);
                               ^
Error: /home/andreas/playground/node_modules/sharp/build/Release/../../lib/libgio-2.0.so.0: undefined symbol: g_option_group_unref
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/andreas/playground/node_modules/sharp/index.js:12:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at [eval]:1:19
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:565:25)
    at startup (node.js:80:7)

@lovell
Copy link
Owner

lovell commented Mar 22, 2016

@papandreou Thanks for checking. I guess the dependencies of glib would also need to be included in the LD_PRELOAD variable, a lot of faff compared with moving a couple of require statements :)

@nsmag Were you also able to "fix" this by altering the require order?

@nsmag
Copy link

nsmag commented Mar 22, 2016

@lovell Sorry for not reporting back.
I decided to do some image processing with raw image data from sharp().raw().
So no need for canvas and I don't want to encounter unexpected surprises in production.

I'll experiment with canvas + sharp again later.

Sharp is lightning fast!
Thanks.

@lovell
Copy link
Owner

lovell commented Mar 30, 2016

Glad you both found workarounds. I'll close this for now but please feel free to comment and/or re-open with any more quick fix solutions :)

@automata
Copy link

I was getting the same libgio-2.0.so.0: undefined symbol: g_option_group_unref error and altering require order (i.e. sharp first, then node-canvas) fixed it.

@lovell
Copy link
Owner

lovell commented Apr 25, 2016

I did experiment with the -Wl,--default-symver linker flag to force the explicit use of shared library version numbering but couldn't get libtiff to play nicely (and even if I had there may have been further walls I wasn't able to hit) :(

@jingsam
Copy link
Contributor

jingsam commented Jun 16, 2016

Any progress to solve this incompatible problem? I got the same error when I uses both sharp and node-canvas

@jingsam
Copy link
Contributor

jingsam commented Jun 17, 2016

When I require sharp before canvas, it seems to solve the problem. However, node-canvas will complain Fontconfig error: Cannot load default config file when drawing text.

@lovell
Copy link
Owner

lovell commented Jun 17, 2016

@jingsam If you're relying on a system-wide installation of cairo for node-canvas, then the absolute safest option here is to also rely on a system-wide install of libvips for sharp.

Repository owner locked and limited conversation to collaborators Jun 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants