23

After upgrading to Ruby 1.9.3 (from 1.9.2 using system RVM) on Ubuntu 10.04.3, I removed all of my gems, and attempted to reinstall pg (ala bundle install pg).

It then threw an error and informed me that I should look at mkmf.log, both of which are included in this gist: https://gist.github.com/d05a81701d968895c730

libpq-dev, libpq5, and postgresql-client are all installed and working correctly. Pointing gem at pg_config, and the include and bin directories directly does not appear to change anything.

I've seen several questions about similar error messages around stackoverflow, and the rest of the web, but they all appear to be simple missing dependency issues (most of them are solved by installing libpq-dev), so I'm at a bit of a loss.

Various other properties that might be useful / relevant:

  • ruby 1.9.3p0 (2011-10-30 revision 33570) [i686-linux]
  • rvm 1.10.1 (system)
  • gem 1.8.15
  • psql (PostgreSQL) 8.4.9

Thanks in advance.

gem_make.out:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/local/rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

ldd.stdout:

$ldd /usr/lib/libpq.so
    linux-gate.so.1 =>  (0xf57fe000)
    libssl.so.0.9.8 => /lib/i686/cmov/libssl.so.0.9.8 (0xb77f4000)
    libcrypto.so.0.9.8 => /lib/i686/cmov/libcrypto.so.0.9.8 (0xb76a2000)
    libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0xb75f1000)
    libcom_err.so.2 => /lib/libcom_err.so.2 (0xb75ec000)
    libgssapi_krb5.so.2 => /usr/lib/libgssapi_krb5.so.2 (0xb75bd000)
    libcrypt.so.1 => /lib/tls/i686/cmov/libcrypt.so.1 (0xb758b000)
    libldap_r-2.4.so.2 => /usr/lib/libldap_r-2.4.so.2 (0xb7544000)
    libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb752b000)
    libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb73d0000)
    libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb73cc000)
    libz.so.1 => /lib/libz.so.1 (0xb73b7000)
    libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0xb7393000)
    libkrb5support.so.0 => /usr/lib/libkrb5support.so.0 (0xb738b000)
    libkeyutils.so.1 => /lib/libkeyutils.so.1 (0xb7386000)
    libresolv.so.2 => /lib/tls/i686/cmov/libresolv.so.2 (0xb7372000)
    /lib/ld-linux.so.2 (0xb786a000)
    liblber-2.4.so.2 => /usr/lib/liblber-2.4.so.2 (0xb7365000)
    libsasl2.so.2 => /usr/lib/libsasl2.so.2 (0xb734d000)
    libgnutls.so.26 => /usr/lib/libgnutls.so.26 (0xb72b2000)
    libtasn1.so.3 => /usr/lib/libtasn1.so.3 (0xb72a0000)
    libgcrypt.so.11 => /lib/libgcrypt.so.11 (0xb722d000)
    libgpg-error.so.0 => /lib/libgpg-error.so.0 (0xb7228000)

pgconfig.stdout:

$pg_config --ldflags --libs

-Wl,-Bsymbolic-functions -Wl,--as-needed -Wl,--as-needed
-lpgport -lxslt -lxml2 -lpam -lssl -lcrypto -lkrb5 -lcom_err -lgssapi_krb5 -lz -lreadline -lcrypt -ldl -lm 

mkmf.log:

find_executable: checking for pg_config... -------------------- yes

--------------------

find_header: checking for libpq-fe.h... -------------------- yes

"gcc -o conftest -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/i686-linux -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1 -I. -I/usr/local/rvm/usr/include  -D_FILE_OFFSET_BITS=64  -I/usr/include/postgresql  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fPIC conftest.c  -L. -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/usr/lib -Wl,-R/usr/local/rvm/usr/lib -L.  -rdynamic -Wl,-export-dynamic -L/usr/lib     -Wl,-R -Wl,/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -lruby  -lpthread -lrt -ldl -lcrypt -lm   -lc"
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main() {return 0;}
/* end */

"gcc -E -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/i686-linux -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1 -I. -I/usr/local/rvm/usr/include  -D_FILE_OFFSET_BITS=64  -I/usr/include/postgresql  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fPIC  conftest.c -o conftest.i"
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <libpq-fe.h>
/* end */

--------------------

find_header: checking for libpq/libpq-fs.h... -------------------- yes

"gcc -E -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/i686-linux -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1 -I. -I/usr/local/rvm/usr/include  -D_FILE_OFFSET_BITS=64  -I/usr/include/postgresql  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fPIC  conftest.c -o conftest.i"
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <libpq/libpq-fs.h>
/* end */

--------------------

have_library: checking for PQconnectdb() in -lpq... -------------------- no

"gcc -o conftest -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/i686-linux -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1 -I. -I/usr/local/rvm/usr/include  -D_FILE_OFFSET_BITS=64  -I/usr/include/postgresql  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fPIC conftest.c  -L. -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/usr/lib -Wl,-R/usr/local/rvm/usr/lib -L.  -rdynamic -Wl,-export-dynamic -L/usr/lib     -Wl,-R -Wl,/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -lruby -lpq  -lpthread -lrt -ldl -lcrypt -lm   -lc"
/usr/lib/libpq.so: undefined reference to `X509_STORE_set_flags@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `CRYPTO_set_locking_callback@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `ENGINE_init@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `ENGINE_free@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `ENGINE_load_private_key@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `ENGINE_finish@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `X509_check_private_key@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `X509_free@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_CTX_new@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_pending@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `TLSv1_method@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `X509_STORE_load_locations@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_CTX_set_verify@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `ERR_pop_to_mark@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_new@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_get_error@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `ERR_get_error@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `ENGINE_by_id@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_write@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_load_error_strings@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_CTX_load_verify_locations@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `BIO_ctrl@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `PEM_read_bio_PrivateKey@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `CRYPTO_set_id_callback@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_free@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `BIO_free@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_CTX_get_cert_store@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `X509_get_subject_name@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_shutdown@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_CTX_set_client_cert_cb@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `PEM_read_bio_X509@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `ERR_set_mark@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `OPENSSL_config@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `X509_NAME_get_text_by_NID@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_read@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_CTX_ctrl@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `ERR_reason_error_string@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_get_peer_certificate@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `X509_NAME_oneline@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_set_ex_data@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_set_fd@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_library_init@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `CRYPTO_num_locks@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_get_ex_data@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `SSL_connect@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `BIO_new_file@OPENSSL_0.9.8'
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <libpq-fe.h>
4: 
5: /*top*/
6: int main() {return 0;}
7: int t() { void ((*volatile p)()); p = (void ((*)()))PQconnectdb; return 0; }
/* end */

"gcc -o conftest -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/i686-linux -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1 -I. -I/usr/local/rvm/usr/include  -D_FILE_OFFSET_BITS=64  -I/usr/include/postgresql  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fPIC conftest.c  -L. -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/usr/lib -Wl,-R/usr/local/rvm/usr/lib -L.  -rdynamic -Wl,-export-dynamic -L/usr/lib     -Wl,-R -Wl,/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -lruby -lpq  -lpthread -lrt -ldl -lcrypt -lm   -lc"
conftest.c: In function 't':
conftest.c:7: error: too few arguments to function 'PQconnectdb'
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <libpq-fe.h>
4: 
5: /*top*/
6: int main() {return 0;}
7: int t() { PQconnectdb(); return 0; }
/* end */

--------------------

have_library: checking for PQconnectdb() in -llibpq... -------------------- no

"gcc -o conftest -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/i686-linux -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1 -I. -I/usr/local/rvm/usr/include  -D_FILE_OFFSET_BITS=64  -I/usr/include/postgresql  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fPIC conftest.c  -L. -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/usr/lib -Wl,-R/usr/local/rvm/usr/lib -L.  -rdynamic -Wl,-export-dynamic -L/usr/lib     -Wl,-R -Wl,/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -lruby -llibpq  -lpthread -lrt -ldl -lcrypt -lm   -lc"
/usr/bin/ld: cannot find -llibpq
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <libpq-fe.h>
4: 
5: /*top*/
6: int main() {return 0;}
7: int t() { void ((*volatile p)()); p = (void ((*)()))PQconnectdb; return 0; }
/* end */

"gcc -o conftest -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/i686-linux -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1 -I. -I/usr/local/rvm/usr/include  -D_FILE_OFFSET_BITS=64  -I/usr/include/postgresql  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fPIC conftest.c  -L. -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/usr/lib -Wl,-R/usr/local/rvm/usr/lib -L.  -rdynamic -Wl,-export-dynamic -L/usr/lib     -Wl,-R -Wl,/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -lruby -llibpq  -lpthread -lrt -ldl -lcrypt -lm   -lc"
conftest.c: In function 't':
conftest.c:7: error: too few arguments to function 'PQconnectdb'
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <libpq-fe.h>
4: 
5: /*top*/
6: int main() {return 0;}
7: int t() { PQconnectdb(); return 0; }
/* end */

--------------------

have_library: checking for PQconnectdb() in -lms/libpq... -------------------- no

"gcc -o conftest -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/i686-linux -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1 -I. -I/usr/local/rvm/usr/include  -D_FILE_OFFSET_BITS=64  -I/usr/include/postgresql  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fPIC conftest.c  -L. -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/usr/lib -Wl,-R/usr/local/rvm/usr/lib -L.  -rdynamic -Wl,-export-dynamic -L/usr/lib     -Wl,-R -Wl,/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -lruby -lms/libpq  -lpthread -lrt -ldl -lcrypt -lm   -lc"
/usr/bin/ld: cannot find -lms/libpq
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <libpq-fe.h>
4: 
5: /*top*/
6: int main() {return 0;}
7: int t() { void ((*volatile p)()); p = (void ((*)()))PQconnectdb; return 0; }
/* end */

"gcc -o conftest -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/i686-linux -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1 -I. -I/usr/local/rvm/usr/include  -D_FILE_OFFSET_BITS=64  -I/usr/include/postgresql  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fPIC conftest.c  -L. -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/usr/lib -Wl,-R/usr/local/rvm/usr/lib -L.  -rdynamic -Wl,-export-dynamic -L/usr/lib     -Wl,-R -Wl,/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -lruby -lms/libpq  -lpthread -lrt -ldl -lcrypt -lm   -lc"
conftest.c: In function 't':
conftest.c:7: error: too few arguments to function 'PQconnectdb'
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <libpq-fe.h>
4: 
5: /*top*/
6: int main() {return 0;}
7: int t() { PQconnectdb(); return 0; }
/* end */

--------------------
Sam Whited
  • 6,880
  • 2
  • 31
  • 37

3 Answers3

65

I've got the same problem in my case was lib's inside .rvm/usr/lib which was taken to this compilation instead of lib's from system. I'm not sure why that happens and why it doesn't work (in my case on Ubuntu 10.04 x86_64) but to solve it just :

 mv ~/.rvm/usr/lib ~/.rvm/usr/lib_rvm

for a while or forever ;)

If someone will investigate why that happen I will be appreciate. Regards.

mtfk
  • 890
  • 6
  • 12
  • 1
    Thank you, thank you, thank you, this finally solved this issue for me after googling around for a few days!! – Thomas Müller Jan 16 '12 at 02:59
  • Thank you; a similar solution appears to have worked for me. I've added this to the bug report. – Sam Whited Jan 16 '12 at 04:51
  • 4
    Eat a chocolate cake from my side :) Spent a day just to install pg gem. – Jashwant Oct 07 '12 at 12:32
  • Except on our Ubuntu 12.04 servers, we get the same error without any rvm. :\ – Joe Atzberger Oct 23 '12 at 19:54
  • Wow what the heck. :O This worked for me as well! I am however baffled; how can something so blatantly wrong/obvious make it to the live version of such a popular software?... Really strange. – dimitarvp Oct 29 '12 at 16:27
  • Same problem and solution for Ubuntu 12.04 Precise Pangolin – chaostheory Oct 30 '12 at 18:49
  • 3
    Is this documented in a bug report anywhere? I'd like to vote on it, because this is the 3rd time it has happened to me... – Dan.StackOverflow Nov 05 '12 at 00:22
  • 2
    From what I could glean from this (https://groups.google.com/forum/#!msg/ruby-pg/oCo8hDHR16A/0y3KdxrPNSMJ) and from Michael Granger's comments in bug reports, the root problem for many who have had this issue is that the ruby executable is linked against one version of OpenSSL whereas the PostgreSQL client libraries are linked against another version. Using the two versions together is asking for trouble (segfault?). If that's correct, then the pg gem would be "wrong" whichever it linked to, and the way forward would be to recompile either PostgreSQL or Ruby so they use the same OpenSSL lib. – antinome Dec 18 '12 at 09:00
  • "recompile PostgreSQL' should read "recompile PostgreSQL client libs" – antinome Dec 18 '12 at 09:09
  • Hmm, I've been thinking more about this and I'm not sure whether my comments above are correct, so please take them with a grain of salt. – antinome Dec 18 '12 at 10:12
  • God, just have the problem, and this helps too ! – Keating Dec 23 '12 at 11:57
  • Tell me an address, and I'll send a pack of beers! – ismriv Feb 11 '13 at 21:41
  • wow ,Thanks a lot .. What is your bank account number .. I will pay in $ ;). We all are layman. You are super man .. – Arpit Vaishnav Feb 13 '13 at 07:16
  • Do we need to move it back after installing the gem ? – Krishna Prasad Varma Feb 14 '13 at 12:25
  • All depend on that if you have there some other libs which are needed. But if you will move them back all should works just fine. All is up to you and your configuration. This hack is needed just for installing pg afterwards you can move them back to make sure that you will not break anything else. – mtfk Feb 14 '13 at 22:55
  • I always keep looking at the internet for the same error, every time I try to install pg gem, until I see this post. Goddamn, why isn't this in first in google? – fotanus Mar 08 '13 at 22:29
  • I have been wrestling with this for hours on a new install of 12.10. I can't believe I even tried this after reading your Answer. That is how desperate I was and, it worked!!! WTF? Thanks! – n8gard Mar 18 '13 at 21:21
  • 1
    You're exactly right, @antinome. Compiling pg against a different version of OpenSSL than your libpq will cause this problem. RVM installs its own private copy of OpenSSL (I assume because it's a newer one or something), which is why moving ~/.rvm/usr/lib aside "fixes" the problem. If you do this, however, keep in mind that your 'openssl' Ruby library may segfault or fail to load, which is a dependency of quite a number of other libraries (net/http comes to mind). If you move it back, then expect segfaults from either 'pg' *or* 'openssl', depending on which version of libssl loads first. – Michael Granger Mar 20 '13 at 07:25
  • Thank you, thank you, thank you! This was the problem. I was pulling my hair out - what's left of it - with this one for a while. Like the OP, lib-pq was in place. – Frank Apr 15 '13 at 01:13
  • OMFG thank you! I've been banging my head off this for about two hours and this sorted it. You star. – Max Williams Jul 30 '13 at 19:04
1

Look at the mkmf.log around line 39:

"gcc -o conftest -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/i686-linux -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1 -I. -I/usr/local/rvm/usr/include  -D_FILE_OFFSET_BITS=64  -I/usr/include/postgresql  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fPIC conftest.c  -L. -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/usr/lib -Wl,-R/usr/local/rvm/usr/lib -L.  -rdynamic -Wl,-export-dynamic -L/usr/lib     -Wl,-R -Wl,/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -L/usr/local/rvm/rubies/ruby-1.9.3-p0/lib -lruby -lpq  -lpthread -lrt -ldl -lcrypt -lm   -lc"
/usr/lib/libpq.so: undefined reference to `X509_STORE_set_flags@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `CRYPTO_set_locking_callback@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `ENGINE_init@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `ENGINE_free@OPENSSL_0.9.8'
/usr/lib/libpq.so: undefined reference to `ENGINE_load_private_key@OPENSSL_0.9.8'
...

Smells like a missing OpenSSL. I also don't see a -lssl in the library list but the missing symbols suggest that it should be there.

So try installing the OpenSSL libraries (version 0.9.8 by the look of things). Then see if pg_config --libs contains -lssl or similar and try again. If all of this works then you might want to send a bug report to the Ubuntu people so that they can fix the libpq-dev dependencies.

Sorry, I don't have an Ubuntu set up anywhere accessible at the moment so there is some guesswork going on here.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • Thanks for your help. Unfortunately, OpenSSL (and all development headers) are installed. The output of pg_config --libs is `-lpgport -lxslt -lxml2 -lpam -lssl -lcrypto -lkrb5 -lcom_err -lgssapi_krb5 -lz -lreadline -lcrypt -ldl -lm`; so it does have -lssl, and nothing else appears to be missing. – Sam Whited Jan 11 '12 at 15:49
  • What does `ldd /usr/lib/libpq.so` output? It should tell you which openssl library it's linked against. – Michael Granger Jan 11 '12 at 16:12
  • I added it to the gist, here: https://gist.github.com/d05a81701d968895c730#file_ldd.stdout – Sam Whited Jan 11 '12 at 16:21
  • @Sam: The configuration script isn't using `pg_config --libs` to get the necessary libraries, any idea why not? – mu is too short Jan 11 '12 at 20:19
  • I'm afraid not; I didn't think it was supposed to. Is there a switch to override them (so I could do something like `--with-pgsql-libs="$(pg_config --libs)"`)? I don't see one, but you never know. – Sam Whited Jan 11 '12 at 21:07
  • @Sam: It should be using `pg_config` as near as I can tell. Have you tried `gem install pg --with-pg-config=/path/to/pg_config` or anything like that? – mu is too short Jan 12 '12 at 01:04
  • Sure did; it seems to find pg_config fine though, so it doesn't make a difference (I used `gem install pg --with-pg-config=$(which pg_config)`) I also double checked, `which pg_config` points to the correct location (no random extra binaries floating around). – Sam Whited Jan 12 '12 at 04:44
  • @Sam: Have you tried `--with-openssl`? I unpacked the gem file and I don't see anywhere that it uses `pg_config --libs` at all (but I could be missing something), I did mind mention of `--with-openssl` though and that might add the missing libraries. – mu is too short Jan 12 '12 at 08:02
  • I hadn't tried that, but unfortunately it didn't seem to change anything. Output is still identical... Thanks for all your help. This problem is starting to drive me mad. I'd like to file a bug report, but I still can't find anything to indicate that it's any more than user error. No idea... – Sam Whited Jan 12 '12 at 16:29
  • @Sam: I'd call it a bug, the gem should be using `pg_config` for the libraries if it is available but it isn't. You should be able to `gem install pg` without anything extra but apparently you can't always do that. – mu is too short Jan 12 '12 at 19:11
  • That's a fair point; I'll have to do that later. Thanks again for all your help. – Sam Whited Jan 12 '12 at 20:34
  • The issue has been reported here, if anyone wants to comment or follow it: https://bitbucket.org/ged/ruby-pg/issue/103/installation-problems-not-related-to-libpq – Sam Whited Jan 12 '12 at 22:50
1

Don't be fooled by the SSL lib being installed - have a look at your Ruby build and check the ssl build log there. I've been bitten by that one before. Other libraries that sometimes don't get loaded are the GZip ones. This may not be the problem but have a look.

UPDATE:

You need the -dev libraries.

These days I use rbenv or one of the other ruby build tools and follow whatever messages they spit out.

Ghoti
  • 2,388
  • 1
  • 18
  • 22
  • Ghoti: I don't see anything funny in there (and the same error happens after a rebuild of 1.9.3, or when building 1.8.7 and 1.9.2, which is odd as it was working fine in 1.9.2 before). But I'll keep digging through the logs and let you know if I find anything. Thanks for the help! – Sam Whited Jan 11 '12 at 17:48