pg_ext.so: 未定义符号: rb_thread_select

pg_ext.so: undefined symbol: rb_thread_select

bash-4.2# rake db:create
/opt/rubystack-2.3.1-0/ruby/bin/.ruby.bin: symbol lookup error: /opt/rubystack-2.3.1-0/ruby/lib/ruby/gems/2.3.0/gems/pg-0.18.4/lib/pg_ext.so: undefined symbol: rb_thread_select
bash-4.2# ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
bash-4.2# rails -v
Rails 4.2.6
bash-4.2# gem list pg

*** LOCAL GEMS ***



  pg (0.18.4, 0.15.1)

有什么问题吗?这是 bitnami 的 ruby 堆栈。

注意:这不是pg版本的bug?请检查我的日志! Ruby 版本 2.3.1,pg 版本 0.18.4.

自 Ruby 1.9.3 以来,rb_thread_select 函数已被弃用。从 Ruby 2.2:

开始,它已被 rb_thread_fd_select 函数取代
VA  VD  VR
old 193 22  rb_thread_select -> rb_thread_fd_select

然而, pg gem has been using the correct function since version 0.15. Here's the relevant section of pg_connection.c @ e5cb1df:

#ifndef HAVE_RB_THREAD_FD_SELECT
#define rb_fdset_t fd_set
#define rb_fd_init(f)
#define rb_fd_zero(f)  FD_ZERO(f)
#define rb_fd_set(n, f)  FD_SET(n, f)
#define rb_fd_term(f)
#define rb_thread_fd_select rb_thread_select
#endif

这些指令是在编译时求值的,因此 C 扩展的共享对象肯定编译不正确。

在构建 pg_ext.so 时一定没有定义 HAVE_RB_THREAD_FD_SELECT 宏。这可能是因为:

  • 它是针对没有 rb_thread_fd_select
  • 的 Ruby 构建的
  • 在构建过程中配置不正确

参考文献: