You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Debian Wheezy: sharp breaks if the canvas module is loaded first #371
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 [email protected][email protected]
[...]
$ 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.
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.
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:
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.
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)
@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?
@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 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.
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) :(
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.
@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 on Jun 17, 2016
Activity
lovell commentedon Mar 2, 2016
I suspect
canvasuses 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.
nsmag commentedon Mar 3, 2016
I got this issue too on Ubuntu 14.04.
Sharp ran fine before I installed the canvas.
lovell commentedon 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:
Failing this, the only option I can think of is to experiment with the
--default-symverlinker flag when building the pre-compiled shared libraries to insert the version number into the symbol table.lovell commentedon Mar 3, 2016
Another even quicker thought:
...should make sharp's bundled glib take precedence regardless of module import order.
papandreou commentedon Mar 22, 2016
Sorry for not reporting back earlier. I just switched around the
requires, then moved on :)... and then it hangs.
If I make the suggested patch to
binding.gypinsidenode_modules/sharp, then runnpm installinsidenode_modules/sharp, I get the original error:lovell commentedon Mar 22, 2016
@papandreou Thanks for checking. I guess the dependencies of glib would also need to be included in the
LD_PRELOADvariable, a lot of faff compared with moving a couple ofrequirestatements :)@nsmag Were you also able to "fix" this by altering the
requireorder?nsmag commentedon 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 commentedon 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 commentedon Apr 25, 2016
I was getting the same
libgio-2.0.so.0: undefined symbol: g_option_group_unreferror and alteringrequireorder (i.e.sharpfirst, thennode-canvas) fixed it.lovell commentedon Apr 25, 2016
I did experiment with the
-Wl,--default-symverlinker flag to force the explicit use of shared library version numbering but couldn't getlibtiffto play nicely (and even if I had there may have been further walls I wasn't able to hit) :(jingsam commentedon Jun 16, 2016
Any progress to solve this incompatible problem? I got the same error when I uses both sharp and node-canvas
jingsam commentedon Jun 17, 2016
When I require
sharpbeforecanvas, it seems to solve the problem. However,node-canvaswill complainFontconfig error: Cannot load default config filewhen drawing text.lovell commentedon Jun 17, 2016
@jingsam If you're relying on a system-wide installation of
cairofornode-canvas, then the absolute safest option here is to also rely on a system-wide install oflibvipsforsharp.