簡體   English   中英

postgres Gem::Ext::BuildError: 在 OSX 上安裝“pg”時,無法構建 gem 本機擴展

[英]postgres Gem::Ext::BuildError: Failed to build gem native extension, when install 'pg' on OSX

我正在 OSX 上開發 Rails 應用程序。
我在 Mac book pro 上獲得了成功,但在執行“捆綁安裝”時在 MacPro 上出現錯誤。
他們的環境幾乎一樣。

os: OSX High Sierra v10.13.4
postgres: v9.6.8 (I installed it by Homebrew)
ruby:
  version: 2.4.2 on MacPro, 2.4.0 on MacBookPro
  installed by: rbenv
  which: /Users/makiaki/.rbenv/shims/ruby
  gem-version: 2.6.13
  bunler-version: 1.16.1

首先,我使用的是 postgresql 10.1 版。
在我的 MacBookPro 中,使用 postgresql 9.6 版獲得了成功。
然后我嘗試卸載postgresql並安裝了 postgresql 9.6 版。
但兩種方式都沒有效果。
exec bundle installbundle install --path vendor/bundle時出現錯誤。

我該如何解決這個問題?

這是控制台:

Fetching pg 0.21.0
Installing pg 0.21.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/makiaki/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/pg-0.21.0/ext
/Users/makiaki/.rbenv/versions/2.4.2/bin/ruby -r ./siteconf20180419-22579-1fcqwvi.rb extconf.rb
checking for pg_config... yes
Using config values from /Users/makiaki/.pyenv/shims/pg_config
pyenv: pg_config: command not found

The `pg_config' command exists in these Python versions:
  anaconda3-4.3.0

pyenv: pg_config: command not found

The `pg_config' command exists in these Python versions:
  anaconda3-4.3.0

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 PQconnectionUsedPassword()... yes
checking for PQisthreadsafe()... yes
checking for PQprepare()... yes
checking for PQexecParams()... yes
checking for PQescapeString()... yes
checking for PQescapeStringConn()... yes
checking for PQescapeLiteral()... yes
checking for PQescapeIdentifier()... yes
checking for PQgetCancel()... yes
checking for lo_create()... yes
checking for pg_encoding_to_char()... yes
checking for pg_char_to_encoding()... yes
checking for PQsetClientEncoding()... yes
checking for PQlibVersion()... yes
checking for PQping()... yes
checking for PQsetSingleRowMode()... yes
checking for PQconninfo()... yes
checking for PQsslAttribute()... yes
checking for rb_encdb_alias()... yes
checking for rb_enc_alias()... yes
checking for rb_thread_call_without_gvl()... yes
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_fd_select()... yes
checking for rb_w32_wrap_io_handle()... no
checking for rb_str_modify_expand()... yes
checking for rb_hash_dup()... yes
checking for PGRES_COPY_BOTH in libpq-fe.h... yes
checking for PGRES_SINGLE_TUPLE in libpq-fe.h... yes
checking for PG_DIAG_TABLE_NAME in libpq-fe.h... yes
checking for struct pgNotify.extra in libpq-fe.h... yes
checking for unistd.h... yes
checking for inttypes.h... yes
checking for ruby/st.h... yes
checking for C99 variable length arrays... yes
creating extconf.h
creating Makefile

current directory: /Users/makiaki/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/pg-0.21.0/ext
make "DESTDIR=" clean

current directory: /Users/makiaki/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/pg-0.21.0/ext
make "DESTDIR="
compiling gvl_wrappers.c
compiling pg.c
compiling pg_binary_decoder.c
compiling pg_binary_encoder.c
compiling pg_coder.c
pg_coder.c:200:34: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        res = this->dec_func(this, val, RSTRING_LEN(argv[0]), tuple, field, ENCODING_GET(argv[0]));
              ~~~~                      ^~~~~~~~~~~~~~~~~~~~
/Users/makiaki/.rbenv/versions/2.4.2/include/ruby-2.4.0/ruby/ruby.h:980:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/Users/makiaki/.rbenv/versions/2.4.2/include/ruby-2.4.0/ruby/ruby.h:976:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pg_coder.c:200:34: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        res = this->dec_func(this, val, RSTRING_LEN(argv[0]), tuple, field, ENCODING_GET(argv[0]));
              ~~~~                      ^~~~~~~~~~~~~~~~~~~~
/Users/makiaki/.rbenv/versions/2.4.2/include/ruby-2.4.0/ruby/ruby.h:981:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
2 warnings generated.
compiling pg_connection.c
compiling pg_copy_coder.c
pg_copy_coder.c:225:15: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                                        strlen = RSTRING_LEN(subint);
                                               ~ ^~~~~~~~~~~~~~~~~~~
/Users/makiaki/.rbenv/versions/2.4.2/include/ruby-2.4.0/ruby/ruby.h:980:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/Users/makiaki/.rbenv/versions/2.4.2/include/ruby-2.4.0/ruby/ruby.h:976:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pg_copy_coder.c:225:15: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                                        strlen = RSTRING_LEN(subint);
                                               ~ ^~~~~~~~~~~~~~~~~~~
/Users/makiaki/.rbenv/versions/2.4.2/include/ruby-2.4.0/ruby/ruby.h:981:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
pg_copy_coder.c:531:23: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                input_len = end_ptr - start_ptr;
                          ~ ~~~~~~~~^~~~~~~~~~~
3 warnings generated.
compiling pg_errors.c
compiling pg_result.c
compiling pg_text_decoder.c
compiling pg_text_encoder.c
pg_text_encoder.c:170:14: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                        len = out - start;
                            ~ ~~~~^~~~~~~
pg_text_encoder.c:289:15: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                return optr - out;
                ~~~~~~ ~~~~~^~~~~
pg_text_encoder.c:293:12: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                return 2 + RSTRING_LEN(*intermediate) * 2;
                ~~~~~~ ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pg_text_encoder.c:501:13: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        nr_elems = RARRAY_LEN(value);
                 ~ ^~~~~~~~~~~~~~~~~
/Users/makiaki/.rbenv/versions/2.4.2/include/ruby-2.4.0/ruby/ruby.h:1026:23: note: expanded from macro 'RARRAY_LEN'
#define RARRAY_LEN(a) rb_array_len(a)
                      ^~~~~~~~~~~~~~~
4 warnings generated.
compiling pg_type_map.c
compiling pg_type_map_all_strings.c
compiling pg_type_map_by_class.c
compiling pg_type_map_by_column.c
pg_type_map_by_column.c:161:52: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        return dec_func( p_coder, RSTRING_PTR(field_str), RSTRING_LEN(field_str), 0, fieldno, enc_idx );
               ~~~~~~~~                                   ^~~~~~~~~~~~~~~~~~~~~~
/Users/makiaki/.rbenv/versions/2.4.2/include/ruby-2.4.0/ruby/ruby.h:980:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/Users/makiaki/.rbenv/versions/2.4.2/include/ruby-2.4.0/ruby/ruby.h:976:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pg_type_map_by_column.c:161:52: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        return dec_func( p_coder, RSTRING_PTR(field_str), RSTRING_LEN(field_str), 0, fieldno, enc_idx );
               ~~~~~~~~                                   ^~~~~~~~~~~~~~~~~~~~~~
/Users/makiaki/.rbenv/versions/2.4.2/include/ruby-2.4.0/ruby/ruby.h:981:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
pg_type_map_by_column.c:230:17: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        conv_ary_len = RARRAY_LEN(conv_ary);
                     ~ ^~~~~~~~~~~~~~~~~~~~
/Users/makiaki/.rbenv/versions/2.4.2/include/ruby-2.4.0/ruby/ruby.h:1026:23: note: expanded from macro 'RARRAY_LEN'
#define RARRAY_LEN(a) rb_array_len(a)
                      ^~~~~~~~~~~~~~~
3 warnings generated.
compiling pg_type_map_by_mri_type.c
compiling pg_type_map_by_oid.c
compiling pg_type_map_in_ruby.c
compiling util.c
util.c:119:24: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        return (char*)out_ptr - out;
        ~~~~~~ ~~~~~~~~~~~~~~~^~~~~
1 warning generated.
linking shared-object pg_ext.bundle
ld: file not found: dynamic_lookup
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_ext.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/makiaki/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/pg-0.21.0 for inspection.
Results logged to /Users/makiaki/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0-static/pg-0.21.0/gem_make.out

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

In Gemfile:
  pg

重點是:

Using config values from /Users/makiaki/.pyenv/shims/pg_config
pyenv: pg_config: command not found

The `pg_config' command exists in these Python versions:
  anaconda3-4.3.0

pyenv: pg_config: command not found

The `pg_config' command exists in these Python versions:
  anaconda3-4.3.0

我試過這個命令: $ which pg_config
它顯示: /Users/makiaki/.pyenv/shims/pg_config
這不好。

修復~/.zshrc像這樣:

# postgres
export PATH="/usr/local/opt/postgresql@9.6/bin:$PATH"

在這種情況下,它是主要問題,把正確的pg_config路徑之前,在我的pyenv PATH設置.zshrc

解決這個問題,獲得成功。

我收到相同的錯誤消息,但日志顯示我遇到了不同的問題:

No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config

運行brew link postgresql解決了它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM