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 @@
 #endif
 #include <string.h>

+#if defined(__APPLE__)
+#include <crt_externs.h>
+#undef environ
+#define environ (*_NSGetEnviron())
+#endif
+
 #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:

1.9.3-p327-patch
build_package_combined_patch() {
  local package_name="$1"

  {
    curl https://raw.github.com/gist/3905045/bf9d1c84c72cdce5be52d8b2dfd4d86a1cdbf185/gistfile1.txt | git apply
    autoconf
    ./configure --prefix="$PREFIX_PATH" $CONFIGURE_OPTS --enable-shared
    make -j 8
    make install
  } >&4 2>&1

}

require_gcc

install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz"
install_package "ruby-1.9.3-p327" "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz" 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