OS X Mavericks下编译代码报头文件找不到的解决办法

最近的业余时间投入了不少精力研究Node.js。在通过NPM安装一些需要编译本地代码,比如说websocket时,直接报错:

[shell]
…node-gyp/0.10.22/deps/v8/include/v8stdint.h:34:19: fatal error: stdio.h: No such file or directory
compilation terminated.
make[1]: *** [Release/obj.target/validation/src/validation.o] Error 1
[/shell]

虽然本地代码不编译也能用,但是性能会有很大影响,所以一直在找解决办法。OS X和*nix系统一样,这些头文件都是在/usr/include目录下面的,在升级到Mavericks之前也编译过不少东西都正常,估计是Mavericks把一些环境变量默认都移除了导致的。

又试了一下XCode,发现编译c、cpp代码都正常,基本就确定了是环境变量的问题。但是又不知道该怎么改,于是一番google,在github的homebrew项目里找到了这么一个issue,里面说到安装XCode后执行一下下面的指令安装一下command-line-tool即可:

[shell]
xcode-select –install
[/shell]

于是试验了一下,发现下载安装完毕之后,果然可以正常编译了:

[shell]
jnduanatmacbookair:websocket jnduan$ make
node-gyp configure build
gyp info it worked if it ends with ok
gyp info using node-gyp@0.12.1
gyp info using node@0.10.22 | darwin | x64
gyp info spawn python
gyp info spawn args [ ‘/usr/local/lib/node_modules/node-gyp/gyp/gyp_main.py’,
gyp info spawn args ‘binding.gyp’,
gyp info spawn args ‘-f’,
gyp info spawn args ‘make’,
gyp info spawn args ‘-I’,
gyp info spawn args ‘/Users/jnduan/code/ajax/node_modules/websocket/build/config.gypi’,
gyp info spawn args ‘-I’,
gyp info spawn args ‘/usr/local/lib/node_modules/node-gyp/addon.gypi’,
gyp info spawn args ‘-I’,
gyp info spawn args ‘/Users/jnduan/.node-gyp/0.10.22/common.gypi’,
gyp info spawn args ‘-Dlibrary=shared_library’,
gyp info spawn args ‘-Dvisibility=default’,
gyp info spawn args ‘-Dnode_root_dir=/Users/jnduan/.node-gyp/0.10.22’,
gyp info spawn args ‘-Dmodule_root_dir=/Users/jnduan/code/ajax/node_modules/websocket’,
gyp info spawn args ‘–depth=.’,
gyp info spawn args ‘–generator-output’,
gyp info spawn args ‘build’,
gyp info spawn args ‘-Goutput_dir=.’ ]
gyp info spawn make
gyp info spawn args [ ‘BUILDTYPE=Release’, ‘-C’, ‘build’ ]
CXX(target) Release/obj.target/validation/src/validation.o
SOLINK_MODULE(target) Release/validation.node
SOLINK_MODULE(target) Release/validation.node: Finished
CXX(target) Release/obj.target/xor/src/xor.o
SOLINK_MODULE(target) Release/xor.node
SOLINK_MODULE(target) Release/xor.node: Finished
gyp info ok
[/shell]

加载评论框需要翻墙