Installing vim with Ruby 1.9.3

by Andrew Stewart
published December 23, 2012

I’ve been running into an issue lately where vim segfaults when I try to use omnicompletion or any vim-based plugins. It’s happened since I started using Ruby 1.9.3. The error messages look something like this:

dyld: lazy symbol binding failed: Symbol not found: _rb_encdb_declare
Referenced from: /Users/stewart/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/x86_64-darwin10.8.0/enc/encdb.bundle
Expected in: flat namespace

dyld: Symbol not found: _rb_encdb_declare
Referenced from: /Users/stewart/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/x86_64-darwin10.8.0/enc/encdb.bundle
Expected in: flat namespace

Vim: Caught deadly signal SEGV

The Fix

After looking around online, I found that the fix is a trivial patch, applied to Ruby before it’s compiled:

diff --git a/missing/setproctitle.c b/missing/setproctitle.c
index 169ba8b..4dc6d03 100644
--- a/missing/setproctitle.c
+++ b/missing/setproctitle.c
@@ -48,6 +48,12 @@
 #include <string.h>

+#if defined(__APPLE__)
+#include <crt_externs.h>
+#undef environ
+#define environ (*_NSGetEnviron())
 #define SPT_NONE   0   /* don't use it at all */
 #define SPT_PSTAT  1   /* use pstat(PSTAT_SETCMD, ...) */
 #define SPT_REUSEARGV  2   /* cover argv with title information */

This stops vim from segfaulting.

What do?

Note: This is assuming you’ve got a setup similar to mine, running OS X, using Homebrew to install packages, and using rbenv/ruby-build to compile/install rubies.

First, uninstall vim:

brew rm vim

Then copy this script:

build_package_combined_patch() {
  local package_name="$1"

    curl | git apply
    ./configure --prefix="$PREFIX_PATH" $CONFIGURE_OPTS --enable-shared
    make -j 8
    make install
  } >&4 2>&1



install_package "yaml-0.1.4" ""
install_package "ruby-1.9.3-p327" "" combined_patch

And put in in a file called 1.9.3-p327-patch.

Then, install it with ruby-build:

rbenv install ./1.9.3-p327-patch

And reinstall vim:

brew install vim