Rails - Gem Error while installing pg (1.2.3)

Help please. How to solve this problem? I cannot install gem ‘pg’…

gem install pg
Building native extensions. This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

    current directory: /home/alex/.rbenv/versions/2.6.6/lib64/ruby/gems/2.6.0/gems/pg-1.2.3/ext
/home/alex/.rbenv/versions/2.6.6/bin/ruby -I /home/alex/.rbenv/versions/2.6.6/lib64/ruby/2.6.0 -r ./siteconf20200827-12823-54e7ke.rb extcon
f.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.
---
find / -name "pg_config" -print
/usr/lib/postgresql10/bin/pg_config
gem install pg -- --with-pg-config=/usr/lib/postgresql10/bin/pg_config 
Building native extensions with: '--with-pg-config=/usr/lib/postgresql10/bin/pg_config'
This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.


    current directory: /home/alex/.rbenv/versions/2.6.6/lib64/ruby/gems/2.6.0/gems/pg-1.2.3/ext
/home/alex/.rbenv/versions/2.6.6/bin/ruby -I /home/alex/.rbenv/versions/2.6.6/lib64/ruby/2.6.0 -r ./siteconf20200827-12620-silryo.rb extconf.rb --with-pg-config\=/usr/lib/postgresql10/bin/pg_config
Using config values from /usr/lib/postgresql10/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 PQsetSingleRowMode()... yes
checking for PQconninfo()... yes
checking for PQsslAttribute()... yes
checking for PQresultVerboseErrorMessage()... yes
checking for PQencryptPasswordConn()... yes
checking for PQresultMemorySize()... yes
checking for timegm()... yes
checking for rb_gc_adjust_memory_usage()... yes
checking for unistd.h... yes
checking for inttypes.h... yes
checking for C99 variable length arrays... yes
creating extconf.h
creating Makefile


current directory: /home/alex/.rbenv/versions/2.6.6/lib64/ruby/gems/2.6.0/gems/pg-1.2.3/ext
make "DESTDIR=" clean


current directory: /home/alex/.rbenv/versions/2.6.6/lib64/ruby/gems/2.6.0/gems/pg-1.2.3/ext
make "DESTDIR="
compiling gvl_wrappers.c
compiling pg.c
In file included from /home/alex/.rbenv/versions/2.6.6/include/ruby-2.6.0/ruby.h:33:0,
                 from pg.h:20,
                 from pg.c:49:
pg.c: In function ‘Init_pg_ext’:
pg.c:470:64: error: ‘PQERRORS_SQLSTATE’ undeclared (first use in this function); did you mean ‘PQERRORS_TERSE’?
  rb_define_const(rb_mPGconstants, "PQERRORS_SQLSTATE", INT2FIX(PQERRORS_SQLSTATE));
                                                                ^
/home/alex/.rbenv/versions/2.6.6/include/ruby-2.6.0/ruby/ruby.h:261:33: note: in definition of macro ‘RB_INT2FIX’
 #define RB_INT2FIX(i) (((VALUE)(i))<<1 | RUBY_FIXNUM_FLAG)
                                 ^
pg.c:470:56: note: in expansion of macro ‘INT2FIX’
  rb_define_const(rb_mPGconstants, "PQERRORS_SQLSTATE", INT2FIX(PQERRORS_SQLSTATE));
                                                        ^~~~~~~
pg.c:470:64: note: each undeclared identifier is reported only once for each function it appears in
  rb_define_const(rb_mPGconstants, "PQERRORS_SQLSTATE", INT2FIX(PQERRORS_SQLSTATE));
                                                                ^
/home/alex/.rbenv/versions/2.6.6/include/ruby-2.6.0/ruby/ruby.h:261:33: note: in definition of macro ‘RB_INT2FIX’
 #define RB_INT2FIX(i) (((VALUE)(i))<<1 | RUBY_FIXNUM_FLAG)
                                 ^
pg.c:470:56: note: in expansion of macro ‘INT2FIX’
  rb_define_const(rb_mPGconstants, "PQERRORS_SQLSTATE", INT2FIX(PQERRORS_SQLSTATE));
                                                        ^~~~~~~
pg.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-self-assign’
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’
cc1: warning: unrecognized command line option ‘-Wno-constant-logical-operand’
cc1: warning: unrecognized command line option ‘-Wno-cast-function-type’
make: *** [Makefile:245: pg.o] Ошибка 1


make failed, exit code 2


Gem files will remain installed in /home/alex/.rbenv/versions/2.6.6/lib64/ruby/gems/2.6.0/gems/pg-1.2.3 for inspection.
Results logged to /home/alex/.rbenv/versions/2.6.6/lib64/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/pg-1.2.3/gem_make.out
cat /etc/os-release
NAME="openSUSE Leap"
VERSION="15.2"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.2"
PRETTY_NAME="openSUSE Leap 15.2"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.2"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/

Why not simply install the pg gem module included with 15.2?

zypper in ruby2.6-rubygem-pg
alex@linux-ofwi:~/.disk_a/Rails/texttospeech> rbenv global 2.6.6alex@linux-ofwi:~/.disk_a/Rails/Heroku/texttospeech> LANG=C sudo zypper in ruby2.6-rubygem-pg
Loading repository data...
Reading installed packages...
'ruby2.6-rubygem-pg' is already installed.
No update candidate for 'ruby2.6-rubygem-pg-1.2.3-lp152.71.2.x86_64'. The highest available version is already installed.
Resolving package dependencies...


Nothing to do.
alex@linux-ofwi:~/.disk_a/Rails/Heroku/texttospeech> bundle update                           
---
Fetching pg 1.2.3 (was 0.21.0)
Installing pg 1.2.3 (was 0.21.0) with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.


    current directory: /home/alex/.disk_a/Rails/Heroku/texttospeech/vendor/bundle/ruby/2.6.0/gems/pg-1.2.3/ext
/home/alex/.rbenv/versions/2.6.6/bin/ruby -I /home/alex/.rbenv/versions/2.6.6/lib64/ruby/2.6.0 -r ./siteconf20200827-15120-1r8w1cb.rb
extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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.


Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib64
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/alex/.rbenv/versions/2.6.6/bin/$(RUBY_BASE_NAME)
        --with-pg
        --without-pg
        --enable-windows-cross
        --disable-windows-cross
        --with-pg-config
        --without-pg-config
        --with-pg_config
        --without-pg_config
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/lib64


To see why this extension failed to compile, please check the mkmf.log which can be found here:


  /home/alex/.disk_a/Rails/Heroku/texttospeech/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0/pg-1.2.3/mkmf.log


extconf failed, exit code 1


Gem files will remain installed in /home/alex/.disk_a/Rails/Heroku/texttospeech/vendor/bundle/ruby/2.6.0/gems/pg-1.2.3 for
inspection.
Results logged to
/home/alex/.disk_a/Rails/Heroku/texttospeech/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0/pg-1.2.3/gem_make.out


An error occurred while installing pg (1.2.3), and Bundler cannot continue.
Make sure that `gem install pg -v '1.2.3' --source 'https://rubygems.org/'` succeeds before bundling.


In Gemfile:
  pg

Since it’s looking for libpq-fe.h, that’s included in the postgresql12-devel package. zypper that in.

it doesn’t work unfortunately …

alex@linux-ofwi:~/.disk_a/Rails/Heroku/texttospeech> LANG=C sudo zypper in postgresql12-devel
[sudo] password for root:  
Retrieving repository 'Main Update Repository' metadata .............................................................................[done]
Building repository 'Main Update Repository' cache ..................................................................................[done]
Loading repository data...
Reading installed packages...
Resolving package dependencies...

Problem: postgresql12-devel-12.4-lp152.18.1.x86_64 conflicts with postgresql-devel-exclusive < 12 provided by postgresql10-devel-10.14-lp15
2.51.1.x86_64
 Solution 1: deinstallation of postgresql10-devel-10.14-lp152.51.1.x86_64
 Solution 2: do not install postgresql12-devel-12.4-lp152.18.1.x86_64

**Choose from above solutions by number or cancel [1/2/c/d/?] (c): **1
Resolving dependencies...
Resolving package dependencies...

The following NEW package is going to be installed:
  postgresql12-devel

The following package is going to be REMOVED:
  postgresql10-devel

1 new package to install, 1 to remove.
Overall download size: 261.2 KiB. Already cached: 0 B. After the operation, 5.0 MiB will be freed.
**Continue? [y/n/v/...? shows all options] (y): **
Retrieving package postgresql12-devel-12.4-lp152.18.1.x86_64                                          (1/1), 261.2 KiB (  1.3 MiB unpacked)
Retrieving: postgresql12-devel-12.4-lp152.18.1.x86_64.rpm .............................................................[done (347.8 KiB/s)]

Checking for file conflicts: ........................................................................................................[done]
(1/2) Removing postgresql10-devel-10.14-lp152.51.1.x86_64 ...........................................................................[done]
Additional rpm output:
warning: file /usr/bin/pg_config: remove failed: No such file or directory                                                                 
warning: file /usr/bin/ecpg: remove failed: No such file or directory                                                                      


(2/2) Installing: postgresql12-devel-12.4-lp152.18.1.x86_64 .........................................................................[done]
  
alex@linux-ofwi:~/.disk_a/Rails/Heroku/texttospeech> bundle update      
----
Fetching pg 1.2.3 (was 0.21.0)
Installing pg 1.2.3 (was 0.21.0) with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/alex/.disk_a/Rails/Heroku/texttospeech/vendor/bundle/ruby/2.6.0/gems/pg-1.2.3/ext
/home/alex/.rbenv/versions/2.6.6/bin/ruby -I /home/alex/.rbenv/versions/2.6.6/lib64/ruby/2.6.0 -r ./siteconf20200827-16370-1k4n9me.rb
extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib64
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/alex/.rbenv/versions/2.6.6/bin/$(RUBY_BASE_NAME)
        --with-pg
        --without-pg
        --enable-windows-cross
        --disable-windows-cross
        --with-pg-config
        --without-pg-config
        --with-pg_config
        --without-pg_config
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/lib64

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/alex/.disk_a/Rails/Heroku/texttospeech/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0/pg-1.2.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/alex/.disk_a/Rails/Heroku/texttospeech/vendor/bundle/ruby/2.6.0/gems/pg-1.2.3 for
inspection.
Results logged to
/home/alex/.disk_a/Rails/Heroku/texttospeech/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0/pg-1.2.3/gem_make.out

An error occurred while installing pg (1.2.3), and Bundler cannot continue.
Make sure that `gem install pg -v '1.2.3' --source 'https://rubygems.org/'` succeeds before bundling.                                      

In Gemfile:
  pg


Looks like he’s on PostgreSQL 10.
Make that adjustment, and you should be fine

zypper in postgresql10-devel

TSU

it was already, I just removed this package.
Please take a look at my previous post.

Any ideas?

It’s in the package specified,
To verify this,
Install the utility locate

zypper in mlocate

After installed, the “locate” database ;updates every 24 hrs, but you won’t want to wait a day so populate it immediately

updatedb

Now, assuming you still have postgresql10-devel installed on your system, locate your file

locate  libpq-fe.h

If at any time you want to verify that it came from the package

rpm -ql postgresql10-devel | grep  libpq-fe.h

After you’ve verified the file exists on your system, that leaves only one likely possibility why your gem isn’t building… It’s likely pointing to a location that’s different than where your file actually is.
There are several ways you can fix this problem…

You can inspect your gem error and see where the file is expected. Either copy your file to the expected location or create a symlink at that location pointing to the real location. Since this is a one shot operation, you can delete the file afterwards so I doubt copying or creating a symlink has any priority. You can also ater the gem build, but that’s likely more difficult than the other choices.

After you’ve built your gem, don’t forget to report it to https://bugzilla.opensuse.org so that the maintainer can fix the problem for others.

TSU

No, I cannot agree with that …
:slight_smile:
Take a look at the output:

gem install pg -v 1.2.3 -- --with-pg-config=/usr/lib/postgresql10/bin/pg_config
Building native extensions with: '--with-pg-config=/usr/lib/postgresql10/bin/pg_config'
This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

    current directory: /home/alex/.rbenv/versions/2.6.4/lib64/ruby/gems/2.6.0/gems/pg-1.2.3/ext
/home/alex/.rbenv/versions/2.6.4/bin/ruby -I /home/alex/.rbenv/versions/2.6.4/lib64/ruby/2.6.0 -r ./siteconf20200829-12881-te4cye.rb extcon
f.rb --with-pg-config\=/usr/lib/postgresql10/bin/pg_config
Using config values from /usr/lib/postgresql10/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 PQsetSingleRowMode()... yes
checking for PQconninfo()... yes
checking for PQsslAttribute()... yes
checking for PQresultVerboseErrorMessage()... yes
checking for PQencryptPasswordConn()... yes
checking for PQresultMemorySize()... yes
checking for timegm()... yes
checking for rb_gc_adjust_memory_usage()... yes
checking for unistd.h... yes
checking for inttypes.h... yes
checking for C99 variable length arrays... yes
creating extconf.h
creating Makefile

current directory: /home/alex/.rbenv/versions/2.6.4/lib64/ruby/gems/2.6.0/gems/pg-1.2.3/ext
make "DESTDIR=" clean

current directory: /home/alex/.rbenv/versions/2.6.4/lib64/ruby/gems/2.6.0/gems/pg-1.2.3/ext
make "DESTDIR="
compiling gvl_wrappers.c
compiling pg.c
In file included from /home/alex/.rbenv/versions/2.6.4/include/ruby-2.6.0/ruby.h:33:0,
                 from pg.h:20,
                 from pg.c:49:
pg.c: In function ‘Init_pg_ext’:
pg.c:470:64: error: ‘PQERRORS_SQLSTATE’ undeclared (first use in this function); did you mean ‘PQERRORS_TERSE’?
  rb_define_const(rb_mPGconstants, "PQERRORS_SQLSTATE", INT2FIX(PQERRORS_SQLSTATE));
                                                                ^
/home/alex/.rbenv/versions/2.6.4/include/ruby-2.6.0/ruby/ruby.h:261:33: note: in definition of macro ‘RB_INT2FIX’
 #define RB_INT2FIX(i) (((VALUE)(i))<<1 | RUBY_FIXNUM_FLAG)
                                 ^
pg.c:470:56: note: in expansion of macro ‘INT2FIX’
  rb_define_const(rb_mPGconstants, "PQERRORS_SQLSTATE", INT2FIX(PQERRORS_SQLSTATE));
                                                        ^~~~~~~
pg.c:470:64: note: each undeclared identifier is reported only once for each function it appears in
  rb_define_const(rb_mPGconstants, "PQERRORS_SQLSTATE", INT2FIX(PQERRORS_SQLSTATE));
                                                                ^
/home/alex/.rbenv/versions/2.6.4/include/ruby-2.6.0/ruby/ruby.h:261:33: note: in definition of macro ‘RB_INT2FIX’
 #define RB_INT2FIX(i) (((VALUE)(i))<<1 | RUBY_FIXNUM_FLAG)
                                 ^
pg.c:470:56: note: in expansion of macro ‘INT2FIX’
  rb_define_const(rb_mPGconstants, "PQERRORS_SQLSTATE", INT2FIX(PQERRORS_SQLSTATE));
                                                        ^~~~~~~
pg.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-self-assign’
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’
cc1: warning: unrecognized command line option ‘-Wno-constant-logical-operand’
cc1: warning: unrecognized command line option ‘-Wno-cast-function-type’
make: *** [Makefile:244: pg.o] Ошибка 1

make failed, exit code 2

Gem files will remain installed in /home/alex/.rbenv/versions/2.6.4/lib64/ruby/gems/2.6.0/gems/pg-1.2.3 for inspection.
Results logged to /home/alex/.rbenv/versions/2.6.4/lib64/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0-static/pg-1.2.3/gem_make.out


The file exists on system:

**checking for libpq-fe.h… yes

**, but gem assembly fails. I don’t know what to do about it, really …

Looks like although dependencies are satisfied, there is an upstream compilation error likely due to a change in supported methods.
Code identified the error, then tried to resolve on its own (apparently there is some error checking and fixes already in the code, maybe errors like this has happened before).
That kind of error isn’t likely going to be solved by an end user, you should submit a bug to https://bugzilla.opensuse.org.

In the meantime,
If you’re in a hurry to deploy a solution,
You can try installing an earlier or later version of PostgreSQL and see if the gem builds correctly.
Or, explore possible gem alternatives.

TSU

OK
https://bugzilla.opensuse.org/show_bug.cgi?id=1175927

Bugzilla refuses to solve this problem, Stackoverflow is silent.
It seems that the problem is just me, and I needlessly bother the respected programmers with my nonsense.
Very sorry. I will have to switch to Fedora…