Skip to content

Installation Windows (with MSYS2)

Caleb Hearon edited this page Aug 10, 2016 · 5 revisions

Part 1 - prepare node-gyp

Follow the instructions here - Installation - Windows#1-installing-node-gyp

Part 2 - install MSYS2 and required packages

  1. Get the latest 64 bit MSYS2 installer from here
  2. In the MSYS2 shell, install cairo and its dependencies with pacman:
pacman -S mingw64/mingw-w64-x86_64-cairo 

and the tools that will be needed to create .lib files for the Visual Studio linker:

pacman -S mingw64/mingw-w64-x86_64-binutils mingw64/mingw-w64-x86_64-tools
  1. Now you just need to generate .lib files for the DLLs you need to link to. To do that:
/mingw64_shell.bat # gives you a MinGW64 shell

gendef /mingw64/bin/libcairo-2.dll
dlltool -d libcairo-2.def -l /mingw64/lib/libcairo-2.lib

gendef /mingw64/bin/libpng16-16.dll
dlltool -d libpng16-16.def -l /mingw64/lib/libpng16-16.lib

rm libcairo-2.def libpng16-16.def
  1. Inside binding.gyp from node-canvas's root, the paths to the lib files are hard-coded on the Windows platform. You will have to edit it. Change GTK_ROOT to be C:/msys64/mingw64, and change png.lib to be libpng16-16.lib and cairo.lib to libcairo-2.lib and then run node-gyp rebuild.

  2. The final step just involves copying all of the DLLs in /mingw64/bin into Canvas's build/Release folder. There are a lot of them, around 20MB worth. You could use Dependency Walker to figure out which ones are really needed, or you can copy them all. After that you're all done!

JPEG, FreeType and Pango support

By hand-editing the binding.gyp you can get all of the features of node-canvas - full Pango, FreeType and JPEG support even with libjpeg-turbo for super fast compression. You just have to generate the .lib files as shown above and edit the GYP file's paths, also don't forget to set the with_<lib> to true at the very top.

Benefits

MSYS is currently the recommended way to get Pango and the whole GTK stack, so you probably won't get more up-to-date libraries any other way. It is possible but difficult to compile Cairo on Windows, and the Installation - Windows wiki does have less steps but the files are at a fixed, older version