Xcode对编译node.js扩展的影响

mac系统下,使用node-gyp编译node.js扩展,总共两步:

1
2
	node-gyp configure
	node-gyp build

悲催的是,两步居然都出了问题
第一步碰上的问题是:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
	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:]))
		//..................
	Exception: Error 2 running xcode-select
	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/node-gyp/lib/configure.js:420:16)
	gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:91:17)
	gyp ERR! stack     at Process._handle.onexit (child_process.js:678:10)
	gyp ERR! System Darwin 12.2.0
	gyp ERR! command "node" "/usr/local/bin/node-gyp" "configure"
	gyp ERR! cwd /JKL/MyWorld/node/c_m/helloWorld
	gyp ERR! node -v v0.8.9
	gyp ERR! node-gyp -v v0.8.3
	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

1
	sudo xcode-select -switch /Applications/Xcode.app/

设置了xcode-select以后,“node-gyp configure”通过,但是“node-gyp build”再次出现问题:

1
2
3
4
5
6
7
8
	gyp info it worked if it ends with ok
	gyp info using node-gyp@0.8.3
	gyp info using node@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”
~~~ok

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

*