Postgresql gem安装pg 0.18.4成功,但bundle install失败。

40

苹果电脑操作系统 El Capitan

使用Bundle安装时出现以下错误:

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.

运行'gem install pg -v '0.18.4'的结果是:

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

然而再次运行'bundle install'仍然失败。有什么建议吗?我已经尝试使用Homebrew卸载和重新安装PostgreSQL,但没有成功。


这个SO线程可能会解决你的问题:https://dev59.com/LWox5IYBdhLWcg3wYzfX - born4new
不幸的是,我尝试了那个线程中的每一个建议,但都没有奏效。 - jasonm
6个回答

107

我现在在macOS Catalina上遇到了相似的错误,但我无法成功运行。

gem install pg -v '0.18.4'

我在 puma gem 中发现了这个问题(我知道这是另一个 gem),这个问题的解决帮助了我:https://github.com/puma/puma/issues/2304

在那里,我找到了以下内容:

Clang 现在默认启用 -Werror=implicit-function-declaration

当您在为 macOS 构建 C 或 Objective-C 代码时使用没有显式声明的函数时,Clang 现在会报告错误(开启了 -Werror=implicit-function-declaration 标志)。这个额外的错误检测统一了 Clang 在 iOS/tvOS 和 macOS 64 位目标上针对此诊断的行为。(49917738)

还有这个:

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

所以,我成功地使用以下命令构建了pg

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

1
花了很多小时来调试它,你的标志解决了我的问题。 - ohiock
4
这也解决了在MacOS Big Sur 11.0 Beta中与pg 0.18.4的问题。 - Mike Szyndel
5
以下步骤适用于我: gem install pg -v '0.18.4' -- --with-cflags="-Wno-error=implicit-function-declaration" - Martin Sommer
1
谢谢!又有一个Big Sur用户被拯救了 - 适用于pg 1.2.3和Postgres 13。 - MrAleister
在Catalina上运行得像魔术一样,谢谢! - Joseworks
显示剩余2条评论

24
所有依赖于本地扩展(如pgpumaffi等)的gem都面临着同样的问题。 我已经通过传递-- --with-cflags="-Wno-error=implicit-function-declaration"来解决了这些问题。
例如:
  • 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"


这对我有用 - 更改@haley-mnatzaganian建议的“config”值出于某种原因无效。 - subelsky
已确认在 Big Sur 上使用 ffi 1.9.23 可以正常工作。 - Tom Harrison

15

在运行bundle之前,我必须像下面这样结合Benito和jasonm的答案(感谢Unixmonkey):

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

1
谢谢!我不得不进行一些小改动才能使其正常工作:bundle config build.pg '--with-cflags="-Wno-error=implicit-function-declaration"'。构建选项需要在没有额外的 -- 前缀的情况下传递。有关更多信息,请参见 https://bundler.io/man/bundle-config.1.html#BUILD-OPTIONS。 - amenon
1
在 macOs Monterey 上,我必须进入 ~/.bundle/config 并将其更改为 BUNDLE_BUILD__PG: "--with-cflags='-Wno-error=implicit-function-declaration'" -- bundle config 命令没有正确转义引号。 - vinhboy
1
对我来说,在删除单引号后,这个命令可以正常工作:bundle config build.pg --with-cflags="-Wno-error=implicit-function-declaration" - Narendra

0

这在我的Sierra上有效:

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

0
这不是一个确切的答案,但它可能会指引你正确的方向…如果gem pg已经成功编译,正如你所说的那样…那么你的Ruby项目可能并没有正确地引用到该gemset。因为当你运行bundle install时,它似乎正在尝试再次安装它,如果pg已经在当前的gemset中被编译和安装,则不应该发生这种情况。你的系统上是否使用了RVM?你能否提供更多输出信息?

不错的想法,但据我所知它们是相同的:jmintz-laptop:radar console$ which gem /Users/USER/.rbenv/shims/gem console$ which bundle /Users/USER/.rbenv/shims/bundle - jasonm

0

答案是安装Postgress.app并运行

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接