Mastodon Polishing Gems

Polishing Gems

20 Oct 2019 | code error gem mac postgresql ruby

The thing about Bundler is that it keeps happening.

I’ve got some hobby projects on heroku and as a side-effect, I periodically need to re-install the pg Ruby gem as part of a bundle install call. Quite often when I do, I am treated to this vexing error (seen in gem_make.out):

    linking shared-object pg_ext.bundle
    ld: file not found: dynamic_lookup
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [pg_ext.bundle] Error 1

Generally bundler tells me to respond to this situation with gem install pg -v ‘1.1.4’ –source ‘https://rubygems.org/’, which will obviously succeed without a lot of fuss. But my Gemfile still angers Bundler.

I have a hard time remembering this important step, which is why it’s now going into my blog. Bundler needs to know where to find an installed pg_config command in order for clang to compile the extensions for the gem. The way I achieve that:

bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config

Apparently this didn’t used to be the place I was finding pg_config because it was set to a different path from my last go-around so this may not be a copypastable solution if stfw brought you here. The fix for you might be to figure out where the correct pg_config is, and then tell Bundler to use it when building whatever gem needs it.