Xcode对编译node.js扩展的影响
发布于 11 年前 作者 jklnode 13093 次浏览 最后一次编辑是 8 年前

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/
5 回复

谢谢分享。Xcode里带developer的package。

windows下也一样报错: d:\Dev\node.js\test\hello\node_modules\socket.io\node_modules\socket.io-client\n ode_modules\ws>node “c:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\ …\node_modules\node-gyp\bin\node-gyp.js” rebuild 在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。 MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,

  1. 安装 .NET Fram ework 2.0 SDK;2) 安装 Microsoft Visual Studio 2005;或 3) 如果将该组件安装到了 其他位置,请将其位置添加到系统 路径中。 [d:\Dev\node.js\test\hello\node_modules\socket.io\node_modules\socket.i o-c lient\node_modules\ws\build\binding.sln] MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,
  2. 安装 .NET Fram ework 2.0 SDK;2) 安装 Microsoft Visual Studio 2005;或 3) 如果将该组件安装到了 其他位置,请将其位置添加到系统 路径中。 [d:\Dev\node.js\test\hello\node_modules\socket.io\node_modules\socket.i o-c lient\node_modules\ws\build\binding.sln]

呵呵,我折腾了一天,mac和win里轮流折腾,总算都能够编译了。不过现在还是停了,因为照着nodejs.org/api/里的例子,开始还行,轮到CreateObject就总是报错了:

dyld: lazy symbol binding failed: Symbol not found: __ZN8MyObject4InitEv
Referenced from: /JKL/MyWorld/node/c_m/create_object/build/Release/addon.node
Expected in: dynamic lookup

dyld: Symbol not found: __ZN8MyObject4InitEv
Referenced from: /JKL/MyWorld/node/c_m/create_object/build/Release/addon.node
Expected in: dynamic lookup

Trace/BPT trap: 5

工作突然开始忙了,也没时间再看它

@jklnode 我也是这个问题到现在不能解决

我想问下这个问题是不是安装vs2005以上的版本就可以解决??

回到顶部