The Error Impeding My Contributions
On my way to contribute to the Rails Guides, after pulling from my cloned copy of the docrails repository on Github and running the bundle install command, an error stopped me:
danieldyba@P4R15 Sat Jun 25 19:35 [ ~/Ruby/docrails ]
>_ bundle install
#... installation of other gems omitted
Installing pg (0.11.0) with native extensions /Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:533:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/bin/ruby 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}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
Gem files will remain installed in /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@DocRails/gems/pg-0.11.0 for inspection.
Results logged to /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@DocRails/gems/pg-0.11.0/ext/gem_make.out
from /Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:511:in `block in build_extensions'
from /Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:486:in `each'
from /Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:486:in `build_extensions'
from /Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:159:in `install'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/source.rb:101:in `block in install'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/rubygems_integration.rb:78:in `preserve_paths'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/source.rb:91:in `install'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/installer.rb:58:in `block (2 levels) in run'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/rubygems_integration.rb:93:in `with_build_args'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/installer.rb:57:in `block in run'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/spec_set.rb:12:in `block in each'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/spec_set.rb:12:in `each'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/spec_set.rb:12:in `each'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/installer.rb:49:in `run'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/installer.rb:8:in `install'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/cli.rb:222:in `install'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/vendor/thor/task.rb:22:in `run'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/vendor/thor.rb:246:in `dispatch'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/vendor/thor/base.rb:389:in `start'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/bin/bundle:13:in `'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/bin/bundle:19:in `load'
from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/bin/bundle:19:in `'
danieldyba@P4R15 Sat Jun 25 19:35 [ ~/Ruby/docrails ]
>_
I am using MacPorts on my machine so if you’re having the same problem and are not using MacPorts then this guide will probably not help you; however, you may learn something that could lead you in the right direction.
Well, I followed the instructions on that error message and looked for my mkmf.log file:
>_ cat /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@DocRails/gems/pg-0.11.0/ext/mkmf.log
find_executable: checking for pg_config... -------------------- no
--------------------
find_header: checking for libpq-fe.h... -------------------- no
"gcc -o conftest -I/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1/x86_64-darwin10.7.0 -I/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1/ruby/backward -I/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -fno-common -pipe conftest.c -L. -L/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/lib -L. -lruby.1.9.1-static -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */
"gcc -E -I/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1/x86_64-darwin10.7.0 -I/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1/ruby/backward -I/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -fno-common -pipe conftest.c -o conftest.i"
conftest.c:3:22: error: libpq-fe.h: No such file or directory
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include /* end */
--------------------
danieldyba@P4R15 Sat Jun 25 20:07 [ ~/Ruby/docrails ]
>_
One Tool Can’t find Another
The trouble seems to be that Bundler can’t find the executable file pg_config. After a little research, I found out that I need to have Postgresql installed on my machine. So I did that with the command:
sudo port install postgresql90
Next, I checked to see where MacPorts installed Postgresql, in particular, where it installed the pg_config file:
>_ find /opt -name pg_config /opt/local/lib/postgresql90/bin/pg_config /opt/local/var/macports/software/postgresql90/9.0.4_0/opt/local/lib/postgresql90/bin/pg_config
Looks like the file is saved in /opt/local/lib/postgresql90/bin/pg_config. I will have to tell Bundler about where the pg_config file is located:
bundle config build.pg --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
That will add a line to my Bundler config file like so:
>_ cat ~/.bundle/config --- BUNDLE_BUILD__PG: --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
And now we’re ready to rock and roll. Run the “bundle install” command again and that error will go away.










