Node.js npm install gif on Mac OS X 64bit

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/cpp
Checking for program ar                  : /usr/bin/ar
Checking for program ranlib              : /usr/bin/ranlib
Checking for g++                         : ok
Checking for node path                   : not found
Checking for node prefix                 : ok /usr/local
Checking 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 bundles
if Options.platform == 'darwin':
if 'i386' in Utils.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 bundles
if Options.platform == 'darwin':
conf.check_tool('osx')

Now compilation and installation work fine.

Be the first to leave a comment. Don’t be shy.

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>