3

When I run

$ gem install pg

I get the following

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

        /usr/bin/ruby.exe 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=/usr/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 /usr/lib/ruby/gems/1.9.1/gems/pg-0.15.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/pg-0.15.1/ext/gem_make.out

When I run

$ gem install pg -- --with-pg-config= /cygdrive/c/Program Files/PostgreSQL/9.0/bin/pg-config

I get the following

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

        /usr/bin/ruby.exe extconf.rb --with-pg-config= /cygdrive/c/Program Files/PostgreSQL/9.0/bin/pg-config
Using config values from
sh: : command not found
sh: : command not found
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-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


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

What does the "sh: : command not found" mean?

Is this the reason why the installation is failing?

Background:

  • I am using Cygwin
  • I used the one click installer of PostgreSQL
  • The pg_config.exe file is located at C/Program Files/PostgreSQL/9.0/bin/pg-config.exe
  • The libpq-fe.h file is located at C/Program Files/PostgreSQL/9.0/include/libpq-fe.h
4

2 回答 2

2

您不能混合和匹配本机 Windows 代码和 Cygwin 代码。如果您想链接到libpq您将需要cygwin版本libpq,并且您需要确保在 上pg_config找到的版本PATH是 cygwin 版本。来自本pg_config机 Windows 构建将产生 Cygwin 工具无法理解的输出,即使它们可以,它们也不会成功链接到本机库并使用它运行。

由于我不再使用 Cygwin,因此无法就当前的安装方式提供任何建议libpq。大概在 Cygwin 的包管理中有一个库,它会被称为postgresql-client,libpq等。

Cygwin 目前是 PostgreSQL 的低优先级平台。鉴于 Ruby+Rails 和 PostgreSQL 都有本机 Windows 版本,您在这方面会遇到困难,我建议您使用这两种工具的本机版本。您仍然可以使用 msys bash 在类似 unix 的 shell 环境中工作,并且如果不能选择 MSVC++,则可以使用 MinGW 的 gcc 生成本机 Windows 可执行文件和库。

于 2013-06-15T08:22:09.637 回答
-1

这对我有用:

sudo apt-get install postgresql
sudo apt-get install libpq-dev

然后

gem install pg
于 2013-08-06T18:31:10.913 回答