trying to install postgres gem on fedora 12 ..

I get these errors :

gem install pg -- --with-pgsql-include-dir='/usr/include/pgsql' -- with-pgsql-lib-dir='/usr/lib/pgsql' Building native extensions. This could take a while... ERROR: Error installing pg:   ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb --with-pgsql-include-dir=/usr/include/pgsql -- with-pgsql-lib-dir=/usr/lib/pgsql can't find header files for ruby.

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/ pg-0.9.0 for inspection. Results logged to /usr/lib/ruby/gems/1.8/gems/pg-0.9.0/ext/ gem_make.out

from yum list postgres*, the relevant stuff I have installed is:

Installed Packages postgresql.i686 8.4.2-1.fc12 @updates postgresql-devel.i686 8.4.2-1.fc12 @updates postgresql-libs.i686 8.4.2-1.fc12 @updates postgresql-server.i686 8.4.2-1.fc12 @updates

I tried to run this with the debuger: ruby -r debug extconf.rb --with-pgsql-include-dir=/usr/include/pgsql -- with-pgsql-lib-dir=/usr/lib/pgsql

this block of code in /usr/lib/ruby/1.8/mkmf.rb is where the error happens

topdir = File.dirname(libdir = File.dirname(__FILE__)) extdir = File.expand_path("ext", topdir) $extmk = File.expand_path($0)[0, extdir.size+1] == extdir+"/" if not $extmk and File.exist?(Config::CONFIG["archdir"] + "/ruby.h")   $hdrdir = $topdir = Config::CONFIG["archdir"] elsif File.exist?(($top_srcdir ||= topdir) + "/ruby.h") and     File.exist?(($topdir ||= Config::CONFIG["topdir"]) + "/config.h")   $hdrdir = $top_srcdir else   abort "can't find header files for ruby." end

it's looking for ruby.h in either: /usr/lib/ruby/1.8/i386-linux /usr/lib/ruby/

and config.h in /usr/lib/ruby/1.8/i386-linux

but those files are not there ..

so I did:

yum install ruby-devel.i686

now I get: can't find libpq-fe.h.

gem install pg -- --with-pgsql-include-dir=/usr/include/pgsql --with- pgsql-lib-dir=/usr/lib/pgsql Building native extensions. This could take a while... ERROR: Error installing pg:   ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb --with-pgsql-include-dir=/usr/include/pgsql -- with-pgsql-lib-dir=/usr/lib/pgsql checking for pg_config... yes 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}/lib   --with-make-prog   --without-make-prog   --srcdir=.   --curdir   --ruby=/usr/bin/ruby   --with-pg   --without-pg   --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}/lib   --enable-static-build   --disable-static-build

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/ pg-0.9.0 for inspection. Results logged to /usr/lib/ruby/gems/1.8/gems/pg-0.9.0/ext/ gem_make.out

so I did:

yum install ruby-devel.i686

now I get: can't find libpq-fe.h.

try

yum install postgresql-devel

I allready have that:

yum install postgresql-devel Loaded plugins: presto, refresh-packagekit Setting up Install Process Package postgresql-devel-8.4.2-1.fc12.i686 already installed and latest version Nothing to do

The file is here: /usr/include/libpq-fe.h

but this doesn't work:

gem install pg -- --with-pgsql-include-dir=/usr/include Building native extensions. This could take a while... ERROR: Error installing pg:   ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb --with-pgsql-include-dir=/usr/include checking for pg_config... yes 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}/lib   --with-make-prog   --without-make-prog   --srcdir=.   --curdir   --ruby=/usr/bin/ruby   --with-pg   --without-pg   --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}/lib   --enable-static-build   --disable-static-build

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/ pg-0.9.0 for inspection. Results logged to /usr/lib/ruby/gems/1.8/gems/pg-0.9.0/ext/ gem_make.out [root@458869-MITLL ext]#

so I have these files in one place:

/usr/include/pgsql/internal/libpq-int.h /usr/include/pgsql/server/libpq/libpq-be.h /usr/include/pgsql/server/libpq/libpq.h /usr/include/pgsql/server/libpq/libpq-fs.h

and then I have this file here: /usr/include/libpq-fe.h

I don't know if that means I have something wrong or incompatible on my system or if I should just try copying the file into the directory with the other ones

so I have these files in one place:

/usr/include/pgsql/internal/libpq-int.h /usr/include/pgsql/server/libpq/libpq-be.h /usr/include/pgsql/server/libpq/libpq.h /usr/include/pgsql/server/libpq/libpq-fs.h

and then I have this file here: /usr/include/libpq-fe.h

I don't know if that means I have something wrong or incompatible on my system or if I should just try copying the file into the directory with the other ones

Try removing and re-installing the postgresql-devel package

yum remove postgresql-devel yum install postgresql-devel

Ok, I just did that, but I am having a problem that my gem command is not working all of a sudden. I had also tried to debug the extconf.rb, I had stepped inside a function that appeared to hang so I killed the process.

gem --help /usr/lib/ruby/site_ruby/1.8/rubygems.rb:521:in `expand_path': No such file or directory - getcwd (Errno::ENOENT)   from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:521:in `find_files'   from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:520:in `map'   from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:520:in `find_files'   from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:1132   from /usr/bin/gem:8:in `require'   from /usr/bin/gem:8

> Try removing and re-installing the postgresql-devel package > > yum remove postgresql-devel > yum install postgresql-devel >

Ok, I just did that, but I am having a problem that my gem command is not working all of a sudden. I had also tried to debug the extconf.rb, I had stepped inside a function that appeared to hang so I killed the process.

gem --help /usr/lib/ruby/site_ruby/1.8/rubygems.rb:521:in `expand_path': No such file or directory - getcwd (Errno::ENOENT)   from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:521:in `find_files'   from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:520:in `map'   from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:520:in `find_files'   from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:1132   from /usr/bin/gem:8:in `require'   from /usr/bin/gem:8

---- getcwd failure seems to indicate that your current path is a directory that no longer exists (like it was deleted)

cd /

then try again

That was strange as 'ls' showed I was in a directory, but that fixed that problem, but after the reinstall I still have the same problem:

also, the extra args don't allways seemed to matter as I get the same error for just "gem install pg" without the other args

gem install pg -- --with-pgsql-include-dir=/usr/include/pgsql --with- pgsql-lib-dir=/usr/lib/pgsql Building native extensions. This could take a while... ERROR: Error installing pg:   ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb --with-pgsql-include-dir=/usr/include/pgsql -- with-pgsql-lib-dir=/usr/lib/pgsql checking for pg_config... yes 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}/lib   --with-make-prog   --without-make-prog   --srcdir=.   --curdir   --ruby=/usr/bin/ruby   --with-pg   --without-pg   --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}/lib   --enable-static-build   --disable-static-build

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/ pg-0.9.0 for inspection. Results logged to /usr/lib/ruby/gems/1.8/gems/pg-0.9.0/ext/ gem_make.out [root@458869-MITLL /]#

(rdb:1) list [683, 692] in /usr/lib/ruby/1.8/mkmf.rb    683 #    684 # For example, if have_header('foo.h') returned true, then the HAVE_FOO_H In trying to debug this, I am not sure if setting a breakpoint inside of a block and not reaching it means that code never executed or could it be peculiar to blocks in ruby. I feel like I want to edit the ruby core stuff and put debug 'puts()' call in it to figure out what is happening ..

   685 # preprocessor macro would be passed to the compiler.    686 #    687 def have_header(header, &b) => 688 checking_for header do    689 if try_cpp(cpp_include(header), &b)    690 $defs.push(format("-DHAVE_%s", header.tr("a-z./\055", "A- Z___")))    691 true    692 else (rdb:1) break 689 Set breakpoint 2 at /usr/lib/ruby/1.8/mkmf.rb:689 (rdb:1) c checking for libpq-fe.h... no Can't find the 'libpq-fe.h header *** extconf.rb failed ***

My code is dying someplace in a log file operation in mkmf.rb while trying to find and process the header file:

module Logging   @log = nil   @logfile = 'mkmf.log'   @orgerr = $stderr.dup   @orgout = $stdout.dup   @postpone = 0

  def self::open     @log ||= File::open(@logfile, 'w')     @log.sync = true     $stderr.reopen(@log)     $stdout.reopen(@log) # <-- execution dies here     yield   ensure     $stderr.reopen(@orgerr)     $stdout.reopen(@orgout)   end

> ---- > getcwd failure seems to indicate that your current path is a directory > that no longer exists (like it was deleted) > > cd / > > then try again >

That was strange as 'ls' showed I was in a directory, but that fixed that problem, but after the reinstall I still have the same problem:

also, the extra args don't allways seemed to matter as I get the same error for just "gem install pg" without the other args

gem install pg -- --with-pgsql-include-dir=/usr/include/pgsql --with- pgsql-lib-dir=/usr/lib/pgsql Building native extensions. This could take a while... ERROR: Error installing pg:   ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb --with-pgsql-include-dir=/usr/include/pgsql -- with-pgsql-lib-dir=/usr/lib/pgsql checking for pg_config... yes 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}/lib   --with-make-prog   --without-make-prog   --srcdir=.   --curdir   --ruby=/usr/bin/ruby   --with-pg   --without-pg   --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}/lib   --enable-static-build   --disable-static-build

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/ pg-0.9.0 for inspection. Results logged to /usr/lib/ruby/gems/1.8/gems/pg-0.9.0/ext/ gem_make.out [root@458869-MITLL /]#

I had put debug prints in the code and the reopen of stdout messed that up. In reality it tries the gcc command below. I did not have gcc installed, I then installed that. When I try the gcc command line from the log I get the error below, except I don't know what directory ruby issues that from:

gcc -E -I. -I/usr/lib/ruby/1.8/i386-linux -I. -D_FILE_OFFSET_BITS=64 - I/usr/include -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions - fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 - mtune=atom -fasynchronous-unwind-tables -fno-strict-aliasing -fPIC conftest.c -o conftest.i gcc: conftest.c: No such file or directory

I deleted the directory as you mentioned and reran it. I have some of my debug print code in the make file utility here in that log file as well:

/usr/bin/ruby extconf.rb checking for pg_config... my in check_for my postpone:mkmftmp1.log my open:mkmf.log step 2 step 3 #<File:mkmf.log> #<IO:0xb78d6f64> yes my check for header checking for libpq-fe.h... my in check_for my postpone:mkmftmp1.log my open:mkmf.log step 2 step 3 #<File:mkmf.log> #<IO:0xb78d6f64> 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}/lib   --with-make-prog   --without-make-prog   --srcdir=.   --curdir   --ruby=/usr/bin/ruby   --with-pg   --without-pg   --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}/lib   --enable-static-build   --disable-static-build [root@458869-MITLL ~]#

I deleted the directory as you mentioned and reran it. I have some of my debug print code in the make file utility here in that log file as well:

/usr/bin/ruby extconf.rb checking for pg_config... my in check_for my postpone:mkmftmp1.log my open:mkmf.log step 2 step 3 #<File:mkmf.log> #<IO:0xb78d6f64> yes my check for header checking for libpq-fe.h... my in check_for my postpone:mkmftmp1.log my open:mkmf.log step 2 step 3 #<File:mkmf.log> #<IO:0xb78d6f64> 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}/lib   --with-make-prog   --without-make-prog   --srcdir=.   --curdir   --ruby=/usr/bin/ruby   --with-pg   --without-pg   --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}/lib   --enable-static-build   --disable-static-build [root@458869-MITLL ~]#

so I just did: yum install gcc-c++ autoconf make

and deleted the ext directory and tried 'gem install pg' and go the same error.

in the mkmf.log I saw this:

ok, it seems to have worked. Thanks alot for your help ..

I tried to be carefull, but I realize that the way ruby functions return default values that debug code in the wrong place can mess up the return result. I often write code to return an explicit result. After not making any sense of why it was erroring our, I restored the non debug version of the mkmf.rb

Jedrin wrote:

I get these errors :

gem install pg -- --with-pgsql-include-dir='/usr/include/pgsql' -- with-pgsql-lib-dir='/usr/lib/pgsql' Building native extensions. This could take a while... ERROR: Error installing pg:   ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb --with-pgsql-include-dir=/usr/include/pgsql -- with-pgsql-lib-dir=/usr/lib/pgsql can't find header files for ruby.

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/ pg-0.9.0 for inspection. Results logged to /usr/lib/ruby/gems/1.8/gems/pg-0.9.0/ext/ gem_make.out

from yum list postgres*, the relevant stuff I have installed is:

Installed Packages postgresql.i686 8.4.2-1.fc12 @updates postgresql-devel.i686 8.4.2-1.fc12 @updates postgresql-libs.i686 8.4.2-1.fc12 @updates postgresql-server.i686 8.4.2-1.fc12 @updates

I had same problem. But It's solved after run

yum install ruby-devel

Thanks.

just in case forks are still struggling with this(at least I was this morning on fedora core 14 beta). I solved the same problem by installing required development tools as:

sudo yum groupinstall 'development tools'

Cheers!

...chad