Ramblings of a techie

Archive for January, 2013

Because of a bug in some node code, all modules try to compile with -arch i386, so after running:

brew install giflib

which is a dependency for the node-gif library, it has only a 64 bit version on your computer. That version is located in:

/usr/local/lib/libgif*

which are symlinked to

/usr/local/Cellar

When running:

npm install gif

the following appears:

Checking for program g++ or c++ : /usr/bin/g++Checking for program cpp : /usr/bin/cppChecking for program ar : /usr/bin/arChecking for program ranlib : /usr/bin/ranlibChecking for g++ : okChecking for node path : not foundChecking for node prefix : ok /usr/localChecking for library gif : not found/Users/meme/node_modules/gif/wscript:17: error: Missing libgif library from giflib package

The actual error is not very helpful; you should check in ~/node_modules/gif/config.log which contains something like this:

./build/config.log:ld: warning: ignoring file Release/test_1.o, file was built for unsupported file format which is not the architecture being linked (i386)./build/config.log:ld: warning: ignoring file /usr/local/lib/libgif.dylib, file was built for unsupported file format which is not the architecture being linked (i386)./build/config.log:Undefined symbols for architecture i386:./build/config.log:ld: symbol(s) not found for architecture i386./build/config.log:[‘/usr/bin/g++’, ‘Release/test_1.o’, ‘-o’, ‘/Users/tycholuyben/node_modules/gif/build/.conf_check_0/testbuild/Release/testprog’, ‘-arch’, ‘i386’, ‘-L/lib’, ‘-L/usr/lib’, ‘-L/usr/local/lib’, ‘-L/usr/local/libgif/lib’, ‘-L/usr/local/giflib/lib’, ‘-L/usr/local/libungif/lib’, ‘-L/usr/local/pkg/giflib-4.1.6/lib’, ‘-lgif’]

Which shows the problem; there is -arch i386 while most libraries on your computer (like giflib) are actually x86_64 archs.

There is a simple way to fix this, open:

/usr/local/lib/node/wafadmin/Tools/node_addon.py, search for i386:

## On Mac OSX we need to use mac bundlesifOptions.platform=='darwin':if'i386'inUtils.cmd_output(['file',nodebin]):conf.env.append_value('CPPFLAGS_NODE',['-arch','i386'])conf.env.append_value('CXXFLAGS_NODE',['-arch','i386'])conf.env.append_value('LINKFLAGS',['-arch','i386'])conf.env['DEST_CPU']='i386'conf.check_tool('osx')

and change to:

## On Mac OSX we need to use mac bundlesifOptions.platform=='darwin':conf.check_tool('osx')