简体   繁体   中英

Postgresql gem install pg 0.18.4 passes, bundle install fails

Mac OS El Capitan

Bundle install fails with:

compiling pg_connection.c
pg_connection.c:2394:3: warning: implicit declaration of function 'gettimeofday' is invalid in C99 [-Wimplicit-function-declaration]
                gettimeofday(&currtime, NULL);
                ^
1 warning generated.
compiling pg_copy_coder.c
compiling pg_errors.c
compiling pg_result.c
compiling pg_text_decoder.c
compiling pg_text_encoder.c
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
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
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/jmintz/Documents/LaunchAngels/radar/vendor/bundle/gems/pg-0.18.4 for inspection.
Results logged to /Users/jmintz/Documents/LaunchAngels/radar/vendor/bundle/extensions/x86_64-darwin-15/2.2.0-static/pg-0.18.4/gem_make.out

... ...

An error occurred while installing pg (0.18.4), and Bundler cannot continue.

Make sure that `gem install pg -v '0.18.4'` succeeds before bundling.

Running 'gem install pg -v '0.18.4' results in:

Building native extensions.  This could take a while...
Successfully installed pg-0.18.4
Parsing documentation for pg-0.18.4
Done installing documentation for pg after 4 seconds
1 gem installed

Yet running 'bundle install' again fails. Any suggestions? I've tried uninstalling and reinstalling postgresql with homebrew with no luck

I have got a similar error now on macOS Catalina, but I was not able to successfully run

gem install pg -v '0.18.4'

I found this issue in the puma gem (I know this is another gem) that helped me solve the issue: https://github.com/puma/puma/issues/2304 .

There, I found this:

Clang now enables -Werror=implicit-function-declaration by default:

Clang now reports an error when you use a function without an explicit declaration when building C or Objective-C code for macOS ( -Werror=implicit-function-declaration flag is on). This additional error detection unifies Clang's behavior for iOS/tvOS and macOS 64-bit targets for this diagnostic. (49917738)

And this:

gem install puma:4.3.5 -- --with-cflags="-Wno-error=implicit-function-declaration"

So, I was able to build pg with:

gem install pg -v '0.18.1' -- --with-cflags="-Wno-error=implicit-function-declaration"

The same issue has been faced with all the gems that rely on native extensions such as pg , puma , ffi , etc I have solved them by passing -- --with-cflags="-Wno-error=implicit-function-declaration"

ex:

  • gem install pg -v '0.18.4' -- --with-cflags="-Wno-error=implicit-function-declaration"

  • gem install ffi -v '1.12.2' -- --with-cflags="-Wno-error=implicit-function-declaration"

  • gem install puma -v '4.3.1' -- --with-cflags="-Wno-error=implicit-function-declaration"

在运行bundle之前,我必须将 Benito 的答案和 jasonm 的答案结合起来,如下所示(归功于 Unixmonkey):

bundle config build.pg '-- --with-cflags="-Wno-error=implicit-function-declaration"'

This isn't an an answer, as such, but it may point you in the right direction... If indeed gem pg has successfully compiled, as you have indicated... Then it maybe that your Ruby project isn't referring to the correct gemset, somehow. As it appears it is attempting to install it again when you bundle install, this should not happen if pg has been compiled and installed in your current gemset. Are you using RVM on your system? Can you also provide more output?

答案是安装 Postgress.app 并运行

  bundle config build.pg --with-pg-config=[Path to pg_config] before bundling

这在 sierra 上对我有用:

gem install pg -v '0.18.3' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config

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