F is for ffi

I was recently setting up on my local machine for a Tech Assessment during an interview process. Lo and behold I came across an error which might look familiar to my fellow devs:

Fetching: ffi-1.9.25.gem (100%)
Building native extensions. This could take a while...
ERROR:  Error installing ffi:
	ERROR: Failed to build gem native extension.
...
make failed, exit code 2

After a quick Google session, I found several posts about this error being encountered. Many of these results offered up a glimmer of hope into why this is occurring. I was expelling whispered sighs of “Of course…must be a brew update…” or “Maybe I have a pending software update” and the ever present, “Damnit Donnie! Why you no work?!”. Here are some of the suggestions I came across, and finally the answer that fixed it for me.

Do as the bundler do

First, what bundler told me to do — run gem install ffi -v '1.11.1' and if that succeeds, then run bundle install again. Nope. Nothing, Make failed. Exit code 2. Thanks. Helpful.

xCode Update?

Second, maybe it’s xcode being xcode-y. Try running xcode-select --install. This gave a handy error of, xcode-select: error: command line tools are already installed, use "Software Update" to install updates.

Too many gems on the dancefloor

Sometimes I forget that I have already installed a gem from an earlier project at a global level using an earlier version. Perhaps I came across this before and the first attempt to fix this did the job. In this case I figured I could try to uninstall the ffi gem incase my assumptions were correct. You can try this by running gem uninstall ffi. To my dismay, although this did uninstall a previous version of the gem ( I believe it was 1.9.21 and I was attempting to install -v 1.11.1 ) trying to install the gem globally again after running the uninstaller still yielded the same error code.

All the world in the tine of a spork

More Googling. More Stack Overflow posts. More pouring through issue notes on GitHub for the ffi gem, jekyll gem, and a couple of other examples where users had similar issues. Finally, like finding the last take-out fork in the back of the drawer in the break-room, I discovered a post that sounded a little out there, but turned out to be correct.

Big shout out to Jamie Macey from Nanaimo, BC ( love your bars by the way! ) for posting the answer. My issue was finally solved and I could move on with my Tech Assessment. It was quite a feeling. To say the least, I was emotional.

A wraith pinned upon the mist

Similar to how I had suspected earlier that I may have multiple versions of the ffi gem installed at the global level, my symlinks to the libraries were incorrectly defined. Not sure if this was an artifact of a recent update to homebrew, or maybe the latest version of xCode, or maybe my own mistake when messing around with npm and react. In either case this was the answer. This was the simple snippet that fixed my issue preventing bundler from progressing down the cascading tree of gems and dependencies.

sudo ln -s /usr/lib/libSystem.B.dylib /usr/local/lib/libgcc_s.10.14.dylib

Some important things to note

You may want to check with your version of MacOS. The post where I discovered this line to change the symlink from the /usr/lib/ directory to the /usr/local/lib/ directory was in regards to the issue being discovered in MacOS Mohave (v 10.4.x). I on the other hand am using MacOS High Sierra (v 10.14.x). I updated my second half of the sudo string to set it to 10.14.dylib rather than 10.4.dylib. You may wan to verify your version and update accordingly.

In case these suggestions in my post haven’t helped your situation as they did for me, here is a link to the discussion thread I found my solution on. Perhaps there is another idea posted here that will work for you. In any case, don’t give up. Keep searching for answers, and when you find yours, consider writing a quick post about it.

Leave a comment

Design a site like this with WordPress.com
Get started