Also at <http://canonical.org/~kragen/compiling-node-on-macos.html>.
I'm trying to get node.js to compile. Unfortunately MacOS doesn't put g++ and gcc in your path even if you install the developer tools, apparently, so I have to stick them in there: export SDK=/Developer/SDKs/MacOSX10.5.sdk export PATH=/Developer/usr/bin:$PATH But given that, `./configure` still fails. The log says it can't find `pthread.h`. The answer ---------- The rest of this document is about how I searched for the answer (although for only three hours, because on MacOS, things Just Work!). The actual answer is quite short. tar xzvf node-v0.4.2.tar.gz cd node-v0.4.2 export PATH=/Developer/usr/bin:$PATH ISYSROOT="-isysroot /Developer/SDKs/MacOSX10.5.sdk" export LINKFLAGS=$ISYSROOT CXXFLAGS=$ISYSROOT CFLAGS=$ISYSROOT ./configure --prefix=$HOME --without-ssl make Note that it is important to have the environment variables set for *both* `./configure` and `make`. Isn't MacOS wonderful? None of those obscure error messages you're used to from Linux, and you can download almost any piece of open-source software, compile it, and it works! A false trail: `C_INCLUDE_PATH`, etc.: -------------------------------------- Well, there's a perfectly good `pthread.h` in `/Developer/SDKs/MacOSX10.5.sdk/usr/include/pthread.h` and also in `/Developer/SDKs/MacOSX10.4u.sdk/usr/include/pthread.h`. It's not obvious why the gcc from the developer package wouldn't find it. But it doesn't, so I gave it a little bit of help (this was the wrong thing to do): export C_INCLUDE_PATH=$SDK/usr/include export CPLUS_INCLUDE_PATH=$SDK/usr/include export LIBRARY_PATH=$SDK/usr/lib That allows `./configure --without-ssl` to complete successfully, even though it was the wrong thing to do. However, `make` still fails to build anything, because it still can't find header files: Waf: Entering directory `/Users/kragen/Downloads/node-v0.4.2/build' [49/73] copy: src/node_config.h.in -> build/default/src/node_config.h [50/73] copy: tools/nodejs.pc.in -> build/default/tools/nodejs.pc [51/73] libv8.a: deps/v8/SConstruct -> build/default/libv8.a /System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python "/Users/kragen/Downloads/node-v0.4.2/tools/scons/scons.py" -j 1 -C "/Users/kragen/Downloads/node-v0.4.2/build/default/" -Y "/Users/kragen/Downloads/node-v0.4.2/deps/v8" visibility=default mode=release arch=ia32 toolchain=gcc library=static snapshot=on scons: Reading SConscript files ... scons: warning: Ignoring missing SConscript 'obj/test/release/SConscript' File "/Users/kragen/Downloads/node-v0.4.2/deps/v8/SConstruct", line 1201, in BuildSpecific scons: done reading SConscript files. scons: Building targets ... g++ -o obj/release/accessors.o -c -Wall -W -Wno-unused-parameter -Wnon-virtual-dtor -pedantic -m32 -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -ansi -mmacosx-version-min=10.4 -fno-rtti -fno-exceptions -Wall -W -Wno-unused-parameter -Wnon-virtual-dtor -pedantic -m32 -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -ansi -mmacosx-version-min=10.4 -DV8_TARGET_ARCH_IA32 -DENABLE_VMSTATE_TRACKING -DENABLE_LOGGING_AND_PROFILING -DENABLE_DEBUGGER_SUPPORT -I/Users/kragen/Downloads/node-v0.4.2/deps/v8/src /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/accessors.cc In file included from /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/../include/v8.h:41, from /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/v8.h:55, from /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/accessors.cc:28: /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/../include/v8stdint.h:33:19: error: stdio.h: No such file or directory (988 more lines of error messages omitted) /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/accessors.cc:906: warning: synthesized method 'virtual v8::internal::TargetCollector::~TargetCollector()' first required here scons: *** [obj/release/accessors.o] Error 1 scons: building terminated because of errors. Waf: Leaving directory `/Users/kragen/Downloads/node-v0.4.2/build' Build failed: -> task failed (err #2): {task: libv8.a SConstruct -> libv8.a} DEST_OS: darwin DEST_CPU: ia32 Parallel Jobs: 1 Product type: program make: *** [program] Error 1 Interestingly, if I copy and paste the `g++` command line myself, I get a different error, which suggests that scons or make or something is removing my `CPLUS_INCLUDE_PATH` (etc.) from the environment: Black-Beauty:node-v0.4.2 kragen$ g++ -o obj/release/accessors.o -c -Wall -W -Wno-unused-parameter -Wnon-virtual-dtor -pedantic -m32 -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -ansi -mmacosx-version-min=10.4 -fno-rtti -fno-exceptions -Wall -W -Wno-unused-parameter -Wnon-virtual-dtor -pedantic -m32 -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -ansi -mmacosx-version-min=10.4 -DV8_TARGET_ARCH_IA32 -DENABLE_VMSTATE_TRACKING -DENABLE_LOGGING_AND_PROFILING -DENABLE_DEBUGGER_SUPPORT -I/Users/kragen/Downloads/node-v0.4.2/deps/v8/src /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/accessors.cc In file included from /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/v8utils.h:32, from /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/v8.h:59, from /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/accessors.cc:28: /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/platform.h:109:18: error: limits: No such file or directory If I unset those variables by hand, I get the same error messages SCons does. Anyway, I'm clearly doing something wrong in the way I'm invoking the compiler, but I don’t know the right way. [Apple’s note “The GCC Compiler Collection on Mac OS X”](http://developer.apple.com/tools/gcc_overview.html) does not help; it does not even suggest that this might be a problem. Searching for stuff like this, I found five-year-old [instructions on compiling `perl`](http://search.cpan.org/~rjbs/perl-5.12.3/README.macosx) which recommend passing hairy `ccflags` and `ldflags` to Perl's `Configure` script. Namely: ./Configure -Accflags="-nostdinc -B$SDK/usr/include/gcc \ -B$SDK/usr/lib/gcc -isystem$SDK/usr/include \ -F$SDK/System/Library/Frameworks" \ -Aldflags="-Wl,-syslibroot,$SDK" \ -de Maybe I can get this to work for Node's configure script. Still, I can't shake the feeling that I must be doing something wrong to run into these problems in the first place. I found [some other guy with the same problem](http://serverfault.com/questions/244406/problems-building-nodejs-on-macos-snow-leopard) but he seems to have given up on building his own binaries and just installing prebuilt binaries using Homebrew. [Some other guy](http://paulsolt.com/2010/11/objective-cc-iphone-build-failures/) has the string `-isysroot /Developer/SDKs/MacOSX10.5.sdk` in his gcc command line... that seems to help: Black-Beauty:node-v0.4.2 kragen$ cd build/default/ Black-Beauty:default kragen$ g++ -o obj/release/accessors.o -c -Wall -W -Wno-unused-parameter -isysroot /Developer/SDKs/MacOSX10.5.sdk -Wnon-virtual-dtor -pedantic -m32 -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -ansi -mmacosx-version-min=10.4 -fno-rtti -fno-exceptions -Wall -W -Wno-unused-parameter -Wnon-virtual-dtor -pedantic -m32 -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -ansi -mmacosx-version-min=10.4 -DV8_TARGET_ARCH_IA32 -DENABLE_VMSTATE_TRACKING -DENABLE_LOGGING_AND_PROFILING -DENABLE_DEBUGGER_SUPPORT -I/Users/kragen/Downloads/node-v0.4.2/deps/v8/src /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/accessors.cc (completes without errors!) Unfortunately, it was not clear to me how to get "waf", invoked by Node's `./configure`, to add this to the `CXXFLAGS` and `CFLAGS`. Advice from IRC --------------- [21:59] <echosystm> if you want to get up and running quickly, you're probably best off just running a linux vm or something [22:00] <echosystm> the latest dev tools wont run on 10.5, as far as i am aware [22:00] <echosystm> and you'll probably need them to build node A solution (?) ============== Black-Beauty:node-v0.4.2 kragen$ LINKFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk' CXXFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk' CFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk' ./configure --prefix=$HOME --without-ssl ... 'configure' finished successfully (2.352s) WARNING WARNING WARNING OpenSSL not found. Will compile Node without crypto support! Black-Beauty:node-v0.4.2 kragen$ make Waf: Entering directory `/Users/kragen/Downloads/node-v0.4.2/build' ... (builds the first 47 files successfully...) ... [47/73] cc: deps/http_parser/http_parser.c -> build/default/deps/http_parser/http_parser_2.o /Developer/usr/bin/gcc -isysroot /Developer/SDKs/MacOSX10.5.sdk -rdynamic -D_GNU_SOURCE -DHAVE_CONFIG_H=1 -pthread -arch i386 -m32 -g -O3 -DEV_FORK_ENABLE=0 -DEV_EMBED_ENABLE=0 -DEV_MULTIPLICITY=0 -DX_STACKSIZE=65536 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DEV_MULTIPLICITY=0 -DHAVE_FDATASYNC=0 -DPLATFORM="darwin" -D__POSIX__=1 -Wno-unused-parameter -D_FORTIFY_SOURCE=2 -DNDEBUG -Idefault/deps/http_parser -I../deps/http_parser ../deps/http_parser/http_parser.c -c -o default/deps/http_parser/http_parser_2.o [49/73] copy: src/node_config.h.in -> build/default/src/node_config.h [50/73] copy: tools/nodejs.pc.in -> build/default/tools/nodejs.pc [51/73] libv8.a: deps/v8/SConstruct -> build/default/libv8.a /System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python "/Users/kragen/Downloads/node-v0.4.2/tools/scons/scons.py" -j 1 -C "/Users/kragen/Downloads/node-v0.4.2/build/default/" -Y "/Users/kragen/Downloads/node-v0.4.2/deps/v8" visibility=default mode=release arch=ia32 toolchain=gcc library=static snapshot=on scons: Reading SConscript files ... scons: warning: Ignoring missing SConscript 'obj/test/release/SConscript' File "/Users/kragen/Downloads/node-v0.4.2/deps/v8/SConstruct", line 1201, in BuildSpecific scons: done reading SConscript files. scons: Building targets ... g++ -o obj/release/accessors.o -c -Wall -W -Wno-unused-parameter -Wnon-virtual-dtor -pedantic -m32 -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -ansi -mmacosx-version-min=10.4 -fno-rtti -fno-exceptions -Wall -W -Wno-unused-parameter -Wnon-virtual-dtor -pedantic -m32 -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -ansi -mmacosx-version-min=10.4 -DV8_TARGET_ARCH_IA32 -DENABLE_VMSTATE_TRACKING -DENABLE_LOGGING_AND_PROFILING -DENABLE_DEBUGGER_SUPPORT -I/Users/kragen/Downloads/node-v0.4.2/deps/v8/src /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/accessors.cc In file included from /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/../include/v8.h:41, from /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/v8.h:55, from /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/accessors.cc:28: /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/../include/v8stdint.h:33:19: error: stdio.h: No such file or directory ... /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/accessors.cc:906: warning: synthesized method 'virtual v8::internal::TargetCollector::~TargetCollector()' first required here scons: *** [obj/release/accessors.o] Error 1 scons: building terminated because of errors. Waf: Leaving directory `/Users/kragen/Downloads/node-v0.4.2/build' Build failed: -> task failed (err #2): {task: libv8.a SConstruct -> libv8.a} make: *** [program] Error 1 Black-Beauty:node-v0.4.2 kragen$ It appears that the `CFLAGS` setting took, but the `CXXFLAGS` setting ([for Waf](http://code.google.com/p/waf/wiki/EnvironmentVariables)) was ignored. Also, though, perhaps the two directories were configured in different ways; it doesn't seem to be invoking `g++` as `/Developer/usr/bin/g++`, even though it invoked `gcc` as `/Developer/usr/bin/gcc`. Hmm, if I supply `CXXFLAGS` directly to `make` as well as to `configure`, I seem to make further progress: Black-Beauty:node-v0.4.2 kragen$ CXXFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk' make ... g++ -o obj/release/accessors.o -c -isysroot /Developer/SDKs/MacOSX10.5.sdk -Wall -W -Wno-unused-parameter -Wnon-virtual-dtor -pedantic -m32 -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -ansi -mmacosx-version-min=10.4 -fno-rtti -fno-exceptions -Wall -W -Wno-unused-parameter -Wnon-virtual-dtor -pedantic -m32 -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -ansi -mmacosx-version-min=10.4 -DV8_TARGET_ARCH_IA32 -DENABLE_VMSTATE_TRACKING -DENABLE_LOGGING_AND_PROFILING -DENABLE_DEBUGGER_SUPPORT -I/Users/kragen/Downloads/node-v0.4.2/deps/v8/src /Users/kragen/Downloads/node-v0.4.2/deps/v8/src/accessors.cc ... This still bombs out at the end with a link command line, which complains: ld: library not found for -lcrt1.10.5.o ...and the corresponding 3.5 kilobyte command line lacks `-isysroot`. Supplying `LINKFLAGS` (**not** `LDFLAGS`) fixes that problem, **and we're done**: Black-Beauty:node-v0.4.2 kragen$ LINKFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk' CXXFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk' make ... Waf: Leaving directory `/Users/kragen/Downloads/node-v0.4.2/build' 'build' finished successfully (29.703s) And `make install` works. <link rel="stylesheet" href="http://canonical.org/~kragen/style.css" /> -- To unsubscribe: http://lists.canonical.org/mailman/listinfo/kragen-tol