Compiling node.js on 32-bit system

I need to compile node.js on a 32-bit system to be compatible with code I already have.

I started with the source code from nodejs.org and compiled it. Then I began by changing lines 164-166 in the common.gypi file. It was:

164           [ 'target_arch=="x64"', {
165             'cflags': [ '-m64' ],
166             'ldflags': [ '-m64' ],
167           }],

and now it is:

164           [ 'target_arch=="x64"', {
165             'cflags': [ '-m32' ],
166             'ldflags': [ '-m32' ],
167           }],

When I tried to make it again, I am getting these errors:

../deps/v8/src/execution.h:259: error: integer constant is too large for 'long' type ../deps/v8/src/execution.h:260: error: integer constant is too large for 'long' type ../deps/v8/src/execution.h:259: error: a function call cannot appear in a constant-expression ../deps/v8/src/execution.h:260: error: a function call cannot appear in a constant-expression

These errors are referring to these lines:

#ifdef V8_TARGET_ARCH_X64
  static const uintptr_t kInterruptLimit = V8_UINT64_C(0xfffffffffffffffe);
  static const uintptr_t kIllegalLimit = V8_UINT64_C(0xfffffffffffffff8);

I believe this code is from google's v8 source code.

I would appreciate any suggestions on either how to fix these particular compiling errors and/or how to compile the 64-bit node.js on a 32-bit system. Most the the research I've done is how to compile something 32-bit for a 64-bit system.

If you want to build an x86_32 version of node, you are modifying the parameters for the wrong target architecture. Instead, give the --dest-cpu parameter to the configure script, like this:

git clone git://github.com/joyent/node.git
cd node
./configure --prefix /usr/local --dest-cpu ia32
make

If these commands finish successfully, there should be a working x86_32 binary in ./out/Release/node:

~/node$ file -b ./out/Release/node
ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), dynamically linked
(uses shared libs), for GNU/Linux 2.6.26, (...), not stripped
~/node$ ./out/Release/node
> 1 + 1
2

You can install it in your running system (at the prefix that you specified in the --prefix parameter above) with sudo make install.

Note that this requires a working C and C++ compiler to be set up. On Debian/Ubuntu, sudo apt-get install build-essential (or build-essential:i386 if you're cross-compiling) should get you started. On rpm-based distributions, try sudo yum groupinstall "Development Tools" "Development Libraries".