Compiling Node.js on OS X Lion

If you are the type of person who is easily distracted by nifty technology you might be thinking that playing with Node.js might be fun. It is. That is all you really need to know, regardless of whether it is a good idea, efficient, innovative, or whatever … it is fun.

In an effort to have some Node.js fun, I downloaded the installer package to my computer and fired it up. It was fun. I wrote some JavaScript. I made a web server that did simple things–fun, fun, fun.

As you might be able to tell, I have hit a difficult part of my PhD and began looking for something to distract myself. Unfortunately, the Node.js fun I was having was not enough. I needed more. I needed to compile Node.js from source (in debug mode) and put in breakpoints and look at things. This is the kind of fun that must be searched out when really big problems arise.

Unfortunately, when I compiled and ran my version of Node.js I ended up with an error that suggested that I had a segmentation fault.

Segmentation fault: 11

Other people had found this as well and the typical response was the “doctor, doctor, it hurts when I do this” response of “well then, don’t do that.” Then they reinstalled Node.js from a package installer or the aforementioned installer download.

Not for me; this promised to be the distraction I had dreamed about. It was back to the Internet to see if anybody else had tackled the problem. And the problem had been reported and fixed and closed and re-opend and fixed and closed and so on. To make a long story short-flavoured, my old Intel-based Macintosh has a hard time with 64-bit compilation and certain structures may need to be defined explicitly to be 64 bits long. The documentation from Apple is minimal, but there is some inline comments in their open source cdefs.h file:

/*
 * _DARWIN_FEATURE_64_BIT_INODE indicates that the ino_t type is 64-bit, and
 * structures modified for 64-bit inodes (like struct stat) will be used.
 */
#if __DARWIN_64_BIT_INO_T
#define _DARWIN_FEATURE_64_BIT_INODE 1
#endif

The short fix (a lazy variant of the fix from here) required me to update the Node.js build configuration file, wscript, to add in the line

conf.env.append_value('CPPFLAGS',  '-D__DARWIN_64_BIT_INO_T')

and with the new compile everything works as I expected it should, at least so far.

Now, I am going to either solve my PhD problem or start writing an add-on module for Node.js using C++. I am even going to see if I can set a breakpoint in my add-on module after trying to work out the calling tree from C++ (Node.js) to JavaScript (scripted program running in Node.js) to C++ (add-on called from JavaScript).

I really hope the PhD problem gets worked out soon.

This entry was posted in Geek Stuff and tagged , , , , , , , , . Bookmark the permalink.

Comments are closed.