Ruby 2.2.3 - "incompatible library version"

Issue #233 invalid
Andy Jones
created an issue

Centos 7, Ruby 2.2.3, PostgreSQL 9.2.14. (Does not happen in Ruby 1.9.3 or 2.3.0)

requiring pg throws the error "LoadError: incompatible library version - blah/blah/blah/pg-0.18.4/lib/pg_ext.so".

A quick transcript to demonstrate and add detail:

jonea@centos7andy[andy/pg_bug]%: gem install pg
Fetching: pg-0.18.4.gem (100%)
Building native extensions.  This could take a while...
Successfully installed pg-0.18.4
Parsing documentation for pg-0.18.4
Installing ri documentation for pg-0.18.4
Done installing documentation for pg after 5 seconds
1 gem installed
  19.60s user 3.13s system 89% cpu 25.479 total
jonea@centos7andy[andy/pg_bug]%: irb
 :001 > require 'pg'
LoadError: incompatible library version - /home/jonea/.rvm/gems/ruby-2.2.3@pgbug/gems/pg-0.18.4/lib/pg_ext.so
        from /home/jonea/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems    /core_ext/kernel_require.rb:54:in `require'
        from /home/jonea/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/jonea/.rvm/gems/ruby-2.2.3@pgbug/gems/pg-0.18.4/lib/pg.rb:4:in `<top (required)>'
        from /home/jonea/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
        from /home/jonea/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
        from /home/jonea/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        from (irb):1
        from /home/jonea/.rvm/rubies/ruby-2.2.3/bin/irb:11:in `<main>'

I first thought this might be issue #229, but apparently not:

jonea@centos7andy[andy/pg_bug]%: ldd ~/.rvm/gems/ruby-2.2.3/gems/pg-0.18.4/lib/pg_ext.so|grep ruby
        libruby.so.2.0 => /usr/lib64/libruby.so.2.0 (0x00007f678ed30000)

(nb: I duplicated the error multiple times, so the mismatch in RVM gemsets between these transcripts is not significant.)

Official response

  • Michael Granger repo owner

    The incompatible library version error means that the version of Ruby the extension was linked against is not the same one that it's being loaded with. This is caused by the environment, either the one used to install the extension or the one present at runtime. It's an error that can happen with any Ruby gem that has an extension, so it's not specific to pg. It's perhaps a bit more complicated with pg because it uses pg_config, so I'm game to try to make it easier to link things correctly, but ultimately it's up to the installer to know how to set up their environment so the dynamic linker sees the same libruby as when the gem was installed.

Comments (18)

  1. Евгений Куликов
    ↪ gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.5.0/bin/pg_config                                                                                     22:15:57
    Fetching: pg-0.18.4.gem (100%)
    Building native extensions with: '--with-pg-config=/usr/local/Cellar/postgresql/9.5.0/bin/pg_config'
    This could take a while...
    Successfully installed pg-0.18.4
    1 gem installed
    kulikov-im at MacBook-Pro-Evgeniy-2 in /u/l/var
    ↪ irb                                                                                                                                                                     22:16:15
    irb(main):001:0> require 'pg'
    /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require': incompatible library version - /Users/kulikov-im/.rvm/gems/ruby-head/gems/pg-0.18.4/lib/pg_ext.bundle (fatal)
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /Users/kulikov-im/.rvm/gems/ruby-head/gems/pg-0.18.4/lib/pg.rb:4:in `<top (required)>'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:128:in `require'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        from (irb):1:in `irb_binding'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb/workspace.rb:86:in `eval'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb/workspace.rb:86:in `evaluate'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb/context.rb:379:in `evaluate'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb.rb:489:in `block (2 levels) in eval_input'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb.rb:623:in `signal_status'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb.rb:486:in `block in eval_input'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb/ruby-lex.rb:245:in `block (2 levels) in each_top_level_statement'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `loop'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `block in each_top_level_statement'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb/ruby-lex.rb:230:in `catch'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb/ruby-lex.rb:230:in `each_top_level_statement'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb.rb:485:in `eval_input'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb.rb:395:in `block in start'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb.rb:394:in `catch'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/lib/ruby/2.3.0/irb.rb:394:in `start'
        from /Users/kulikov-im/.rvm/rubies/ruby-head/bin/irb:11:in `<main>'
    

    OS: Darwin 15.3.0 Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64

    OSX El Capitan

    Ruby: 2.3

    PostgreSQL: 9.5

  2. Sylvain B

    Same problem here with ruby 2.2.3, pg 0.18.4, PostgreSQL 9.5.1 and Arch Linux. I've just updated my PostgreSQL installation from 9.4 to 9.5 and the problem appear...

    $ rake db:setup
    rake aborted!
    LoadError: incompatible library version - /home/sylvain/.rvm/gems/ruby-2.2.3@fab-manager/gems/pg-0.18.1/lib/pg_ext.so
    

    Any solutions or workaround ?

    EDIT: I just fixed the issue by upgrading to ruby 2.3, as suggested in this comment

  3. Jimmy Karily

    I downgraded to postgres 9.4.5 and I get the same error (pg-0.18.4, ruby 2.2.4p230, Arch linux)

    /home/dimitris/.rvm/gems/ruby-2.2.4/gems/pg-0.18.4/lib/pg.rb:4:in `require': incompatible library version - /home/dimitris/.rvm/gems/ruby-2.2.4/gems/pg-0.18.4/lib/pg_ext.so (LoadError)
        from /home/dimitris/.rvm/gems/ruby-2.2.4/gems/pg-0.18.4/lib/pg.rb:4:in `<top (required)>'
        from /home/dimitris/.rvm/gems/ruby-2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in `require'
        from /home/dimitris/.rvm/gems/ruby-2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in `block (2 levels) in require'
        from /home/dimitris/.rvm/gems/ruby-2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
        from /home/dimitris/.rvm/gems/ruby-2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
        from /home/dimitris/.rvm/gems/ruby-2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
    
  4. Jimmy Karily

    Running ldd on the library shows that the system libruby (with a wrong version) is linked (I've downgraded to 0.18.1 on this example but same thing happens on 0.18.4) :

    ~/workspace/testributor/katana (master)*$ ldd /home/dimitris/.rvm/gems/ruby-2.2.4/gems/pg-0.18.1/lib/pg_ext.so 
        linux-vdso.so.1 (0x00007ffffa17f000)
        libruby.so.2.3 => /usr/lib/libruby.so.2.3 (0x00007f4966578000)
        libpq.so.5 => /usr/lib/libpq.so.5 (0x00007f4966349000)
        libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f496612c000)
        libgmp.so.10 => /usr/lib/libgmp.so.10 (0x00007f4965eb3000)
        libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f4965caf000)
        libcrypt.so.1 => /usr/lib/libcrypt.so.1 (0x00007f4965a78000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007f4965772000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f49653d1000)
        /usr/lib64/ld-linux-x86-64.so.2 (0x00005571b2aba000)
        libssl.so.1.0.0 => /usr/lib/libssl.so.1.0.0 (0x00007f4965160000)
        libcrypto.so.1.0.0 => /usr/lib/libcrypto.so.1.0.0 (0x00007f4964ce8000)
        libgssapi_krb5.so.2 => /usr/lib/libgssapi_krb5.so.2 (0x00007f4964a9c000)
        libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0x00007f49647b7000)
        libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0x00007f4964586000)
        libcom_err.so.2 => /usr/lib/libcom_err.so.2 (0x00007f4964382000)
        libkrb5support.so.0 => /usr/lib/libkrb5support.so.0 (0x00007f4964174000)
        libkeyutils.so.1 => /usr/lib/libkeyutils.so.1 (0x00007f4963f70000)
        libresolv.so.2 => /usr/lib/libresolv.so.2 (0x00007f4963d59000)
    

    It seems that this issue is the same with this: https://bitbucket.org/ged/ruby-pg/issues/229/pg_ext-improperly-linked-when-using-rvm

  5. Michael Granger repo owner

    The incompatible library version error means that the version of Ruby the extension was linked against is not the same one that it's being loaded with. This is caused by the environment, either the one used to install the extension or the one present at runtime. It's an error that can happen with any Ruby gem that has an extension, so it's not specific to pg. It's perhaps a bit more complicated with pg because it uses pg_config, so I'm game to try to make it easier to link things correctly, but ultimately it's up to the installer to know how to set up their environment so the dynamic linker sees the same libruby as when the gem was installed.

  6. Joseph Maloney

    @Michael Granger relatively new to all of this and im running into this issue and i would bet that its an issue with my environment set up. my question is how do figure it out? which files will show the version that was linked and and how might i change this? I can't seem to find anything on this besides this issue/thread so I'm hoping you can help me.

  7. Wayne Mattingly

    I had this problem and it was nerve racking. I experienced the problem when I switched to Ubuntu 16.04 LTS, I did not have this on 14.04 LTS. How I fixed it was. Also you may want to update Ubuntu "sudo apt-get update". That may do it as well because 16.04 LTS just released a lot of new patches for postgresql.

    sudo apt-get install g++

    sudo apt-get install build-essential

  8. Log in to comment