Don't Forget to Plant It!

Installing Native Gems With Custom Library Paths

A few weeks ago, I started using the Patron Gem for Skribit and ran into an issue on our CentOS production servers which uses a very old version of libcurl.  I got it working by compiling a new version of libcurl and building the Gem against those binaries.  Since I didn’t want to overwrite the libcurl that CentOS provided, I installed the binaries in another location instead, and updated the LD_LIBRARY_PATH environment variable so Rails could properly load the Gem.

A couple of days ago, Paul brought to my attention that using LD_LIBRARY_PATH isn’t a good thing.  While I didn’t necessarily think it was a big deal, it did peak my curiosity on how I would get this work without it.  Here’s the command I finally used to get it to work:

1
2
3
sudo env PATH="/opt/curl/bin:$PATH" gem install toland-patron \
-v "0.4.1" --source http://gems.github.com \
-- --with-ldflags="-Wl,-R/opt/curl/lib"

The key part is the –with-ldflags option at the very end.  The -Wl,-R<path> option adds the given path to the list of paths the linker will use to find libraries at runtime.  Hopefully, someone will find this information useful, since I couldn’t find this information myself on the ‘nets anywhere.

Comments