mac系统下,使用node-gyp编译node.js扩展,总共两步: node-gyp configure node-gyp build
悲催的是,两步居然都出了问题 第一步碰上的问题是:
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.' ]
xcode-select: Error: No Xcode is selected. Use xcode-select -switch <path-to-xcode>, or see the xcode-select manpage (man xcode-select) for further information.
Traceback (most recent call last):
File "/usr/local/lib/node_modules/node-gyp/gyp/gyp", line 18, in <module>
sys.exit(gyp.main(sys.argv[1:]))
//..................
gyp ERR! not ok
xcode-select: Error: No Xcode is selected. Use xcode-select -switch <path-to-xcode>, or see the xcode-select manpage (man xcode-select) for further information.
第一反应是,node.js和Xcode有毛关系,google“path-to-xcode”,发现还真是有问题:我的系统曾经装过早期版本的xcode,是默认装在developer系统下,但是最新版本的xcode是在Applications目录里,虽然这对xcode没影响(至少我没发现),但是看起来是对里面的c++模块有影响,具体啥情况,我也不晓得~~只要知道解决方案就可以了: 重新设置xcode-select指到你的Xcode.app
sudo xcode-select -switch /Applications/Xcode.app/
设置了xcode-select以后,“node-gyp configure”通过,但是“node-gyp build”再次出现问题:
gyp info it worked if it ends with ok
gyp info using node-gyp[@0](/user/0).8.3
gyp info using node[@0](/user/0).8.9 | darwin | x64
gyp ERR! build error
gyp ERR! stack Error: not found: make
gyp ERR! stack at F (/usr/local/lib/node_modules/node-gyp/node_modules/which/which.js:43:28)
//..........
gyp ERR! not ok
对configure/make这种玩意本来就不熟,于是有迷茫了一阵,继续google,发现据说是缺少GCC(GNU Compiler Collection,GNU编译器集合),还是需要通过Xcode解决: 打开Xcode -> Preferences -> Downloads -> Command Line Tools -> install -> Reboot 下载这个100多M的东西,用了些时间,然后再次“node-gyp build”
------------
原载:http://www.jiangkunlun.com/2013/01/mac_node-gyp_c_node-js/