Skip to content

Instantly share code, notes, and snippets.

@caike
Last active December 20, 2015 14:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caike/6148957 to your computer and use it in GitHub Desktop.
Save caike/6148957 to your computer and use it in GitHub Desktop.
Installing pg gem on Ruby 2.0

Installing pg gem on Ruby 2.0

When installing the pg gem on Ruby 2.0 I ran into the following issues:

pg.c: In function ‘pg_s_library_version’:
pg.c:272: warning: implicit declaration of function ‘PQlibVersion’
pg.c: In function ‘Init_pg_ext’:
pg.c:375: error: ‘PQPING_OK’ undeclared (first use in this function)
pg.c:375: error: (Each undeclared identifier is reported only once
pg.c:375: error: for each function it appears in.)
pg.c:377: error: ‘PQPING_REJECT’ undeclared (first use in this function)
pg.c:379: error: ‘PQPING_NO_RESPONSE’ undeclared (first use in this function)
pg.c:381: error: ‘PQPING_NO_ATTEMPT’ undeclared (first use in this function)
make: *** [pg.o] Error 1

To solve this:

  1. run locate pg_config
  2. Find the binary (mine is /usr/local/bin/pg_config)
  3. gem install pg -v '0.16.0' -- with-pg-config=/usr/local/bin/pg_config

UPDATE #1: If this still fails with pg version 0.16.0, then downgrade to version 0.15.1 and it should work. Add the following to your Gemfile: gem 'pg', '~> 0.15.1'

UPDATE #2: When I really came to need version 0.16.0, I simply re-installed postgresql via homebrew (updating homebrew was probably what broke everything in the first place)

@olivierlacan
Copy link

Humblebrag: rails/rails@58d69a5 😄

@bruceyue
Copy link

/Users/Bruce/.rvm/rubies/ruby-2.0.0-p247/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 pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... yes
checking for PQconnectionUsedPassword()... yes
checking for PQisthreadsafe()... yes
checking for PQprepare()... yes
checking for PQexecParams()... yes
checking for PQescapeString()... yes
checking for PQescapeStringConn()... yes
checking for PQescapeLiteral()... yes
checking for PQescapeIdentifier()... yes
checking for PQgetCancel()... yes
checking for lo_create()... yes
checking for pg_encoding_to_char()... yes
checking for pg_char_to_encoding()... yes
checking for PQsetClientEncoding()... yes
checking for PQlibVersion()... yes
checking for PQping()... yes
checking for PQsetSingleRowMode()... no
checking for rb_encdb_alias()... yes
checking for rb_enc_alias()... no
checking for rb_thread_call_without_gvl()... yes
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_fd_select()... yes
checking for rb_w32_wrap_io_handle()... no
checking for PGRES_COPY_BOTH in libpq-fe.h... no
checking for PGRES_SINGLE_TUPLE in libpq-fe.h... no
checking for PG_DIAG_TABLE_NAME in libpq-fe.h... no
checking for struct pgNotify.extra in libpq-fe.h... yes
checking for unistd.h... yes
checking for ruby/st.h... yes
creating extconf.h
creating Makefile

make
compiling gvl_wrappers.c
compiling pg.c
pg.c: In function ‘pg_s_library_version’:
pg.c:272: warning: implicit declaration of function ‘PQlibVersion’
pg.c: In function ‘Init_pg_ext’:
pg.c:375: error: ‘PQPING_OK’ undeclared (first use in this function)
pg.c:375: error: (Each undeclared identifier is reported only once
pg.c:375: error: for each function it appears in.)
pg.c:377: error: ‘PQPING_REJECT’ undeclared (first use in this function)
pg.c:379: error: ‘PQPING_NO_RESPONSE’ undeclared (first use in this function)
pg.c:381: error: ‘PQPING_NO_ATTEMPT’ undeclared (first use in this function)
make: *** [pg.o] Error 1

Gem files will remain installed in /Users/Bruce/.rvm/gems/ruby-2.0.0-p247/gems/pg-0.16.0 for inspection.
Results logged to /Users/Bruce/.rvm/gems/ruby-2.0.0-p247/gems/pg-0.16.0/ext/gem_make.out

@caike
Copy link
Author

caike commented Aug 19, 2013

Hey @bruceyue, try downgrading it to pg version 0.15.1. Still having some issues with the latest 0.16.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment