在 Apple Silicon M1 上使用 Ruby 3.0.2 在 MacOS Monterey 上安装 sqlite3 时出错

Posted

技术标签:

【中文标题】在 Apple Silicon M1 上使用 Ruby 3.0.2 在 MacOS Monterey 上安装 sqlite3 时出错【英文标题】:Error with gem install sqlite3 on MacOS Monterey with Ruby 3.0.2 on Apple Silicon M1 【发布时间】:2021-12-30 12:50:58 【问题描述】:

当我在 Ruby 3.0.2 的全新 rbenv 安装下尝试 gem install sqlite3 时遇到错误。 sqlite3 gem 在 Ruby 2.7.4 下成功安装。有什么办法解决这个问题?

我在 Apple Silicon M1 机器上使用 MacOS Monterey。

➜  ~ > rbenv shell 3.0.2
➜  ~ > gem install sqlite3
Fetching sqlite3-1.4.2.gem
Building native extensions. This could take a while…
ERROR:  Error installing sqlite3:
    ERROR: Failed to build gem native extension.

    current directory: /Users/brian/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/sqlite3-1.4.2/ext/sqlite3
/Users/brian/.rbenv/versions/3.0.2/bin/ruby -I /Users/brian/.rbenv/versions/3.0.2/lib/ruby/3.0.0 -r ./siteconf20211119-57074-7hi3f4.rb extconf.rb
checking for sqlite3.h… yes
checking for pthread_create() in -lpthread… yes
checking for -ldl… yes
checking for sqlite3_libversion_number() in -lsqlite3… yes
checking for rb_proc_arity()… yes
checking for rb_integer_pack()… yes
checking for sqlite3_initialize()… yes
checking for sqlite3_backup_init()… yes
checking for sqlite3_column_database_name()… yes
checking for sqlite3_enable_load_extension()… yes
checking for sqlite3_load_extension()… yes
checking for sqlite3_open_v2()… yes
checking for sqlite3_prepare_v2()… yes
checking for sqlite3_int64 in sqlite3.h… yes
checking for sqlite3_uint64 in sqlite3.h… yes
creating Makefile

current directory: /Users/brian/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/sqlite3-1.4.2/ext/sqlite3
make DESTDIR\= clean

current directory: /Users/brian/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/sqlite3-1.4.2/ext/sqlite3
make DESTDIR\=
compiling aggregator.c
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:23:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/defines.h:73:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/backward/2/attributes.h:43:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/attr/pure.h:25:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/assert.h:132:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:24:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/anyargs.h:77:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/intern/vm.h:64:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:25:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic.h:23:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic/char.h:23:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic/int.h:26:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic/long.h:70:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:25:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic.h:23:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic/char.h:29:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:28:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rbasic.h:46:14: error: expected parameter declarator
RUBY_ALIGNAS(SIZEOF_VALUE)
             ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/value.h:41:23: note: expanded from macro 'SIZEOF_VALUE'
# define SIZEOF_VALUE SIZEOF_LONG
                      ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/arm64-darwin21/ruby/config.h:61:21: note: expanded from macro 'SIZEOF_LONG'
#define SIZEOF_LONG 8
                    ^
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:25:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic.h:23:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic/char.h:29:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:28:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rbasic.h:46:14: error: expected ')'
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/value.h:41:23: note: expanded from macro 'SIZEOF_VALUE'
# define SIZEOF_VALUE SIZEOF_LONG
                      ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/arm64-darwin21/ruby/config.h:61:21: note: expanded from macro 'SIZEOF_LONG'
#define SIZEOF_LONG 8
                    ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rbasic.h:46:1: note: to match this '('
RUBY_ALIGNAS(SIZEOF_VALUE)
^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/backward/2/stdalign.h:27:22: note: expanded from macro 'RUBY_ALIGNAS'
#define RUBY_ALIGNAS RBIMPL_ALIGNAS
                     ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/stdalign.h:66:44: note: expanded from macro 'RBIMPL_ALIGNAS'
# define RBIMPL_ALIGNAS(_) __declspec(align(_))
                                           ^
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:25:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic.h:23:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic/char.h:29:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:28:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rbasic.h:47:1: error: expected function body after function declarator
RBasic 
^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rbasic.h:82:23: error: incomplete definition of type 'struct RBasic'
    return RBASIC(obj)->klass;
           ~~~~~~~~~~~^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rbasic.h:82:12: note: forward declaration of 'struct RBasic'
    return RBASIC(obj)->klass;
           ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rbasic.h:34:50: note: expanded from macro 'RBASIC'
#define RBASIC(obj)          RBIMPL_CAST((struct RBasic *)(obj))
                                                 ^
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:25:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic.h:23:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic/char.h:29:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:30:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:35:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/value_type.h:157:28: error: incomplete definition of type 'struct RBasic'
    VALUE ret = RBASIC(obj)->flags & RUBY_T_MASK;
                ~~~~~~~~~~~^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/value_type.h:157:17: note: forward declaration of 'struct RBasic'
    VALUE ret = RBASIC(obj)->flags & RUBY_T_MASK;
                ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rbasic.h:34:50: note: expanded from macro 'RBASIC'
#define RBASIC(obj)          RBIMPL_CAST((struct RBasic *)(obj))
                                                 ^
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:25:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic.h:23:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic/char.h:29:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:30:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:237:23: error: incomplete definition of type 'struct RBasic'
    return RBASIC(obj)->flags & flags;
           ~~~~~~~~~~~^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:237:12: note: forward declaration of 'struct RBasic'
    return RBASIC(obj)->flags & flags;
           ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rbasic.h:34:50: note: expanded from macro ‘RBASIC’
#define RBASIC(obj)          RBIMPL_CAST((struct RBasic *)(obj))
                                                 ^
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:25:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic.h:23:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic/char.h:29:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:30:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:285:1: error: ‘__declspec’ attributes are not enabled; use ‘-fdeclspec’ or ‘-fms-extensions’ to enable support for __declspec attributes
RBIMPL_ATTR_NOALIAS()
^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/attr/noalias.h:53:32: note: expanded from macro ‘RBIMPL_ATTR_NOALIAS’
# define RBIMPL_ATTR_NOALIAS() __declspec(noalias)
                               ^
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:25:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic.h:23:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic/char.h:29:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:30:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:288:30: warning: declaration of ‘struct RBasic’ will not be visible outside of this function [-Wvisibility]
rbimpl_fl_set_raw_raw(struct RBasic *obj, VALUE flags)
                             ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:290:8: error: incomplete definition of type 'struct RBasic'
    obj->flags |= flags;
    ~~~^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:288:30: note: forward declaration of ‘struct RBasic’
rbimpl_fl_set_raw_raw(struct RBasic *obj, VALUE flags)
                             ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:298:27: warning: incompatible pointer types passing ‘struct RBasic *’ to parameter of type ‘struct RBasic *’ [-Wincompatible-pointer-types]
    rbimpl_fl_set_raw_raw(RBASIC(obj), flags);
                          ^~~~~~~~~~~
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rbasic.h:34:30: note: expanded from macro ‘RBASIC’
#define RBASIC(obj)          RBIMPL_CAST((struct RBasic *)(obj))
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/cast.h:33:28: note: expanded from macro ‘RBIMPL_CAST’
# define RBIMPL_CAST(expr) (expr)
                           ^~~~~~
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:288:38: note: passing argument to parameter ‘obj’ here
rbimpl_fl_set_raw_raw(struct RBasic *obj, VALUE flags)
                                     ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:310:1: error: ‘__declspec’ attributes are not enabled; use ‘-fdeclspec’ or ‘-fms-extensions’ to enable support for __declspec attributes
RBIMPL_ATTR_NOALIAS()
^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/attr/noalias.h:53:32: note: expanded from macro ‘RBIMPL_ATTR_NOALIAS’
# define RBIMPL_ATTR_NOALIAS() __declspec(noalias)
                               ^
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:25:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic.h:23:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic/char.h:29:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:30:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:313:32: warning: declaration of ‘struct RBasic’ will not be visible outside of this function [-Wvisibility]
rbimpl_fl_unset_raw_raw(struct RBasic *obj, VALUE flags)
                               ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:315:8: error: incomplete definition of type 'struct RBasic'
    obj->flags &= ~flags;
    ~~~^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:313:32: note: forward declaration of ‘struct RBasic’
rbimpl_fl_unset_raw_raw(struct RBasic *obj, VALUE flags)
                               ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:323:29: warning: incompatible pointer types passing ‘struct RBasic *’ to parameter of type ‘struct RBasic *’ [-Wincompatible-pointer-types]
    rbimpl_fl_unset_raw_raw(RBASIC(obj), flags);
                            ^~~~~~~~~~~
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rbasic.h:34:30: note: expanded from macro ‘RBASIC’
#define RBASIC(obj)          RBIMPL_CAST((struct RBasic *)(obj))
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/cast.h:33:28: note: expanded from macro ‘RBIMPL_CAST’
# define RBIMPL_CAST(expr) (expr)
                           ^~~~~~
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:313:40: note: passing argument to parameter ‘obj’ here
rbimpl_fl_unset_raw_raw(struct RBasic *obj, VALUE flags)
                                       ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:335:1: error: ‘__declspec’ attributes are not enabled; use ‘-fdeclspec’ or ‘-fms-extensions’ to enable support for __declspec attributes
RBIMPL_ATTR_NOALIAS()
^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/attr/noalias.h:53:32: note: expanded from macro ‘RBIMPL_ATTR_NOALIAS’
# define RBIMPL_ATTR_NOALIAS() __declspec(noalias)
                               ^
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:25:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic.h:23:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic/char.h:29:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:30:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:338:34: warning: declaration of ‘struct RBasic’ will not be visible outside of this function [-Wvisibility]
rbimpl_fl_reverse_raw_raw(struct RBasic *obj, VALUE flags)
                                 ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:340:8: error: incomplete definition of type 'struct RBasic'
    obj->flags ^= flags;
    ~~~^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:338:34: note: forward declaration of ‘struct RBasic’
rbimpl_fl_reverse_raw_raw(struct RBasic *obj, VALUE flags)
                                 ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:348:31: warning: incompatible pointer types passing ‘struct RBasic *’ to parameter of type ‘struct RBasic *’ [-Wincompatible-pointer-types]
    rbimpl_fl_reverse_raw_raw(RBASIC(obj), flags);
                              ^~~~~~~~~~~
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rbasic.h:34:30: note: expanded from macro 'RBASIC'
#define RBASIC(obj)          RBIMPL_CAST((struct RBasic *)(obj))
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/cast.h:33:28: note: expanded from macro 'RBIMPL_CAST'
# define RBIMPL_CAST(expr) (expr)
                           ^~~~~~
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:338:42: note: passing argument to parameter 'obj' here
rbimpl_fl_reverse_raw_raw(struct RBasic *obj, VALUE flags)
                                         ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:465:43: error: incomplete definition of type 'struct RBasic'
        if (RBASIC_CLASS(x) && !(RBASIC(x)->flags & RUBY_FL_SINGLETON)) 
                                 ~~~~~~~~~^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/fl_type.h:465:34: note: forward declaration of 'struct RBasic'
        if (RBASIC_CLASS(x) && !(RBASIC(x)->flags & RUBY_FL_SINGLETON)) 
                                 ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rbasic.h:34:50: note: expanded from macro 'RBASIC'
#define RBASIC(obj)          RBIMPL_CAST((struct RBasic *)(obj))
                                                 ^
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:25:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic.h:23:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/arithmetic/char.h:29:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:74:19: error: field has incomplete type 'struct RBasic'
    struct RBasic basic;
                  ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:74:12: note: forward declaration of 'struct RBasic'
    struct RBasic basic;
           ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:109:26: error: incomplete definition of type 'struct RBasic'
    VALUE f = RBASIC(str)->flags;
              ~~~~~~~~~~~^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:74:12: note: forward declaration of ‘struct RBasic’
    struct RBasic basic;
           ^
In file included from aggregator.c:1:
In file included from ./aggregator.h:4:
In file included from ./sqlite3_ruby.h:4:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby.h:38:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/ruby.h:26:
In file included from /Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core.h:23:
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rarray.h:88:19: error: field has incomplete type ‘struct RBasic’
    struct RBasic basic;
                  ^
/Users/brian/.rbenv/versions/3.0.2/include/ruby-3.0.0/ruby/internal/core/rstring.h:74:12: note: forward declaration of ‘struct RBasic’
    struct RBasic basic;
           ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
6 warnings and 20 errors generated.
make: *** [aggregator.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/brian/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/sqlite3-1.4.2 for inspection.
Results logged to /Users/brian/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/extensions/arm64-darwin-21/3.0.0/sqlite3-1.4.2/gem_make.out

➜  ~ >

【问题讨论】:

【参考方案1】:

我想出了答案。如果我在gem install 命令前面加上CC='clang -fdeclspec',它就可以工作。

像这样:

CC='clang -fdeclspec' gem install sqlite3

【讨论】:

以上是关于在 Apple Silicon M1 上使用 Ruby 3.0.2 在 MacOS Monterey 上安装 sqlite3 时出错的主要内容,如果未能解决你的问题,请参考以下文章

在 M1 芯片上运行 rails 时出错(Apple Silicon)

Android Emulator 在 M1 mac/Apple Silicon 上卡住了加载屏幕

在 Apple Silicon M1 上使用 Ruby 3.0.2 在 MacOS Monterey 上安装 sqlite3 时出错

解决在Apple Silicon (M1)安装php MongoDB扩展失败

如何在 Apple Silicon M1 上原生安装 NodeJS?

在具有 M1 芯片(基于 ARM 的 Apple Silicon)的 Mac 上安装较早版本的 Python(3.8 之前)失败