Npm安装Canvas出现如下提示
npm http GET https://registry.npmjs.org/canvas
npm http GET https://registry.npmjs.org/canvas
npm http 304 https://registry.npmjs.org/canvas
npm http GET https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/nan
> [email protected] install /Users/jinyachen/nodejs/graduation/node-plus/node_modules/canvas
> node-gyp rebuild
./util/has_cairo_freetype.sh: line 4: pkg-config: command not found
gyp: Call to ‘./util/has_cairo_freetype.sh‘ returned exit status 0.
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:337:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Darwin 13.1.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/jinyachen/nodejs/graduation/node-plus/node_modules/canvas
gyp ERR! node -v v0.10.25
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the canvas package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls canvas
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 13.1.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/jinyachen/nodejs/graduation/node-plus
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.24
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/jinyachen/nodejs/graduation/node-plus/npm-debug.log
npm ERR! not ok code 0
Github 有人说:
Try adding the following to your environment variables. Took me a while to figure this
out. And this could be an invalid solution depending on how you installed pkgconfig or cairo.
Lion and Earlier: $ export PKG_CONFIG_PATH=/usr/X11/lib/pkgconfig
Mountain Lion:
$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
(官网有对上面的说明,对于官网的说明,我在这里不再进行讲述。由于我已经执行了 红字的命令,所以后面的操作没有再添加这个环境变量)
即将pkgconfig添加到环境变量。但是我没有成功。
后来找了找,看了下官方wiki,https://github.com/LearnBoost/node-canvas/wiki/Installation---OSX
官方提示的 是查看系统是否安装了pkgconfig,我看了下,木有安装,所以要先按照pkgconfig。。。
$ curl http://pkgconfig.freedesktop.org/releases/pkg-config-0.23.tar.gz -o pkgconfig.tgz
$ tar -zxf pkgconfig.tgz && cd pkg-config-0.23
$ ./configure && make install
在 make阶段报错:
duplicate
symbol _g_bit_nth_lsf in:
testglib.o
./.libs/libglib.a(gutils.o)
duplicate symbol _g_bit_nth_msf in:
testglib.o
./.libs/libglib.a(gutils.o)
duplicate symbol _g_bit_storage in:
testglib.o
./.libs/libglib.a(gutils.o)
ld: 45 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [testglib] Error 1
make[2]: *** [install-recursive] Error 1
make[1]: *** [install] Error 2
make: *** [install-recursive] Error 1
搜索了一下,说是修改C文件的某行代码。。但是我实在是找不到那个文件
所以下了个目前最新的 pkg-config-0.28 版本(觉得他们应该在新版本里修复这个问题了)
configure的时候报错
configure: error: Either a previously installed pkg-config or "glib-2.0 >= 2.16" could not be found. Please set GLIB_CFLAGS and GLIB_LIBS to the correct values or pass --with-internal-glib
to configure to use the bundled copy.
Google了一下,再加上看官方文档,在 ./configure 后面加了 --with-internal-glib
$ ./configure --with-internal-glib
$ make install
运行顺利,但是执行make install的时候提示权限错误
然后我用sudo重新编译安装了一遍,没有错误提示。(以后的编译和安装都需要sudo提权)
之后回到要按照canvas的工程,执行npm
install canvas,发现缺少cairo.
ok,返回canvas的官方wiki发现要安装cairo,还要安装他的依赖包
pixman。
通过前面的教训,我直接到官网下载最新版本的pixman
(pixman-0.32.4 2014.5.20)。
安装的时候注意提权。
$ ./configure --prefix=/usr/local --disable-dependency-tracking
$ sudo make install
pixman顺利安装,虽然有许多warning,但是毕竟没有error
然而在按装cairo (cairo-1.12.16)
的时候,configure报错
Could not find libpng in the pkg-config search path
只好去libpng官方下载源码包进行安装
http://www.libpng.org/pub/png/libpng.html,安装方法一样configure 然后make install,一切正常。
然后返回cairo目录下 执行编译和按装
$ ./configure --prefix=/usr/local --disable-dependency-tracking
$ sudo make install
按照顺利,虽然
warning: argument unused during compilation
这个提示一直不断。。。
下面回到nodejs的工程目录。。。。
npm install canvas
安装顺利,warning不断。
--------------------------------------------------------------------------------------------------------------------------------------------
安装的包(按照安装顺序排列,安装时注意提权)
pkg-config-0.28 (注意 --with-internal-glib参数)
pixman-0.32.4
libpng-1.6.10
cairo-1.12.16.tar
--------------------------------------------------------------------------------------------------------------------------------------------
Wll done!!!开始使用 Node-Canvas吧!
安装 node-canvas 遇到的各种问题,布布扣,bubuko.com