pg 1.0.0`致命错误:' libpq-fe.h'文件未找到

时间:2018-05-10 11:38:26

标签: ruby-on-rails ruby rubygems clang

安装pg(1.0.0)时出错,Bundler无法继续

我遇到捆绑安装问题,无法完成安装。

如何完成捆绑?

  find_executable: checking for pg_config... -------------------- no

    --------------------

    find_header: checking for libpq-fe.h... -------------------- no

    "clang -o conftest -I/Users/leotyndall/.rbenv/versions/2.4.2/include/ruby-2.4.0/x86_64-darwin17 -I/Users/leotyndall/.rbenv/versions/2.4.2/include/ruby-2.4.0/ruby/backward -I/Users/leotyndall/.rbenv/versions/2.4.2/include/ruby-2.4.0 -I. -I/Users/leotyndall/.rbenv/versions/2.4.2/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -Wno-error=shorten-64-to-32  -pipe conftest.c  -L. -L/Users/leotyndall/.rbenv/versions/2.4.2/lib -L. -L/Users/leotyndall/.rbenv/versions/2.4.2/lib  -fstack-protector -L/usr/local/lib     -lruby-static -framework CoreFoundation  -lpthread -ldl -lobjc "
    checked program was:
    /* begin */
    1: #include "ruby.h"
    2: 
    3: int main(int argc, char **argv)
    4: {
    5:   return 0;
    6: }
    /* end */

        "clang -E -I/Users/leotyndall/.rbenv/versions/2.4.2/include/ruby-2.4.0/x86_64-darwin17 - 
             I/Users/leotyndall/.rbenv/versions/2.4.2/include/ruby- 
         2.4.0/ruby/backward - 
         I/Users/leotyndall/.rbenv/versions/2.4.2/include/ruby-2.4.0 -I. - 
         I/Users/leotyndall/.rbenv/versions/2.4.2/include  -D_XOPEN_SOURCE - 
         D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -Wno- 
         error=shorten-64-to-32  -pipe  conftest.c -o conftest.i"
         conftest.c:3:10: fatal error: 'libpq-fe.h' file not found
         #include <libpq-fe.h>
             ^~~~~~~~~~~~
         1 error generated.
         checked program was:
         /* begin */
         1: #include "ruby.h"
         2: 
         3: #include <libpq-fe.h>
        /* end */

    --------------------


     extconf failed, exit code 1


        An error occurred while installing pg (1.0.0), and Bundler cannot continue.
        Make sure that `gem install pg -v '1.0.0'` succeeds before bundling.

4 个答案:

答案 0 :(得分:2)

尝试为您的操作系统安装libpq-dev或其等价物:

  • 对于Ubuntu系统:sudo apt-get install libpq-dev
  • Red Hat Linux(RHEL)系统上:yum install postgresql-devel
  • 适用于Mac Homebrewbrew install postgresql
  • 对于Mac MacPorts PostgreSQL:gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config
  • OpenSusezypper in postgresql-devel

答案 1 :(得分:2)

对于macOS,以上答案对我而言不起作用或不切实际。我不想安装所有的postgres。

$ brew install libpq
$ bundle config --local build.pg --with-opt-dir="/usr/local/opt/libpq"
$ bundle install

参考:https://michaelrigart.be/install-pg-ruby-gem-without-postgresql/

答案 2 :(得分:1)

brew install libpq

gem install pg -v '1.2.3' --source 'https://rubygems.org/' -- --with-pg-config=/opt/homebrew/Cellar/libpq/13.2/bin/pg_config

答案 3 :(得分:0)

我通过安装库解决了这个问题

brew install libpqxx

接下来,正常安装pg ...可以使用gem

gem install pg