简体   繁体   中英

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

I am developing Rails Application on OSX.
I got success on my Mac book pro, but I got error on MacPro when exec 'bundle install'.
Their environment are almost same.

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

Firstly, I was using postgresql version 10.1.
In my MacBookPro, got success with postgresql version 9.6.
Then I tried to uninstall postgresql and installed postgresql version 9.6.
But both way is not effectiveness.
I have got error when exec bundle install or bundle install --path vendor/bundle .

How can I fix this problem?

And this is console:

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

The point is that:

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

I tried this command: $ which pg_config
It shows: /Users/makiaki/.pyenv/shims/pg_config
It is not good.

Fixing ~/.zshrc such like this:

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

In this case, it is the mainly problem to put correct pg_config PATH before pyenv PATH setting in my .zshrc .

Fixing that, getting success.

I was getting the same error message, but the log showed I was having a different issue:

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

Running brew link postgresql resolved it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM