如何在 M1 Mac 上安装 sqlite3 gem?

jay*_*jay 4 sqlite ruby-on-rails

我正在尝试在运行 M1 Pro 芯片的 Mac 上安装sqlite3-ruby gem。

\n

安装失败并显示以下输出:

\n
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.\n\n    current directory: /Users/jay/.frum/versions/3.1.0/lib/ruby/gems/3.1.0/gems/sqlite3-1.4.2/ext/sqlite3\n/Users/jay/.frum/versions/3.1.0/bin/ruby -I /Users/jay/.frum/versions/3.1.0/lib/ruby/3.1.0 -r ./siteconf20220215-37077-7vshdb.rb extconf.rb\nchecking for sqlite3.h... yes\nchecking for pthread_create() in -lpthread... yes\nchecking for -ldl... yes\nchecking for sqlite3_libversion_number() in -lsqlite3... no\nsqlite3 is missing. Try \'brew install sqlite3\',\n\'yum install sqlite-devel\' or \'apt-get install libsqlite3-dev\'\nand check your shared library search path (the\nlocation where your sqlite3 shared library is located).\n*** extconf.rb failed ***\nCould not create Makefile due to some reason, probably lack of necessary\nlibraries and/or headers.  Check the mkmf.log file for more details.  You may\nneed configuration options.\n
Run Code Online (Sandbox Code Playgroud)\n

查看该mkmf.log文件,有许多错误似乎与错误架构的编译过程构建有关:

\n
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/jay/.frum/versions/3.1.0/lib pkg-config --exists sqlite3\nDYLD_FALLBACK_LIBRARY_PATH=.:/Users/jay/.frum/versions/3.1.0/lib pkg-config --libs sqlite3 |\n=> "-L/opt/homebrew/Cellar/sqlite/3.37.2/lib -lsqlite3\\n"\nDYLD_FALLBACK_LIBRARY_PATH=.:/Users/jay/.frum/versions/3.1.0/lib "clang -o conftest -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/arm64-darwin21 -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/ruby/backward -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef  -pipe conftest.c  -L. -L/Users/jay/.frum/versions/3.1.0/lib -L. -fstack-protector-strong -L/usr/local/lib     -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc   "\nld: warning: ignoring file /Users/jay/.frum/versions/3.1.0/lib/libruby.3.1-static.a, building for macOS-x86_64 but attempting to link with file built for macOS-arm64\nchecked program was:\n/* begin */\n1: #include "ruby.h"\n2: \n3: int main(int argc, char **argv)\n4: {\n5:   return !!argv[argc];\n6: }\n/* end */\n\nDYLD_FALLBACK_LIBRARY_PATH=.:/Users/jay/.frum/versions/3.1.0/lib "clang -o conftest -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/arm64-darwin21 -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/ruby/backward -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef  -pipe conftest.c  -L. -L/Users/jay/.frum/versions/3.1.0/lib -L. -fstack-protector-strong -L/usr/local/lib     -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc -L/opt/homebrew/Cellar/sqlite/3.37.2/lib -lsqlite3  "\nld: warning: ignoring file /Users/jay/.frum/versions/3.1.0/lib/libruby.3.1-static.a, building for macOS-x86_64 but attempting to link with file built for macOS-arm64\nld: warning: ignoring file /opt/homebrew/Cellar/sqlite/3.37.2/lib/libsqlite3.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64\nchecked program was:\n/* begin */\n1: #include "ruby.h"\n2: \n3: int main(int argc, char **argv)\n4: {\n5:   return !!argv[argc];\n6: }\n/* end */\n\nDYLD_FALLBACK_LIBRARY_PATH=.:/Users/jay/.frum/versions/3.1.0/lib pkg-config --cflags-only-I sqlite3 |\n=> "-I/opt/homebrew/Cellar/sqlite/3.37.2/include\\n"\nDYLD_FALLBACK_LIBRARY_PATH=.:/Users/jay/.frum/versions/3.1.0/lib pkg-config --cflags-only-other sqlite3 |\n=> "\\n"\nDYLD_FALLBACK_LIBRARY_PATH=.:/Users/jay/.frum/versions/3.1.0/lib pkg-config --libs-only-l sqlite3 |\n=> "-lsqlite3\\n"\npackage configuration for sqlite3\nincflags: -I/opt/homebrew/Cellar/sqlite/3.37.2/include\ncflags: \nldflags: -L/opt/homebrew/Cellar/sqlite/3.37.2/lib\nlibs: -lsqlite3\n\nfind_header: checking for sqlite3.h... -------------------- yes\n\nDYLD_FALLBACK_LIBRARY_PATH=.:/Users/jay/.frum/versions/3.1.0/lib "clang -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/arm64-darwin21 -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/ruby/backward -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0 -I. -I/opt/homebrew/Cellar/sqlite/3.37.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef  -pipe    -c conftest.c"\nchecked program was:\n/* begin */\n1: #include "ruby.h"\n2: \n3: #include <sqlite3.h>\n/* end */\n\n--------------------\n\nfind_library: checking for pthread_create() in -lpthread... -------------------- yes\n\nDYLD_FALLBACK_LIBRARY_PATH=.:/Users/jay/.frum/versions/3.1.0/lib "clang -o conftest -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/arm64-darwin21 -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/ruby/backward -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0 -I. -I/opt/homebrew/Cellar/sqlite/3.37.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef  -pipe  conftest.c  -L. -L/Users/jay/.frum/versions/3.1.0/lib -L. -fstack-protector-strong -L/usr/local/lib -L/opt/homebrew/Cellar/sqlite/3.37.2/lib     -lsqlite3 -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc -lpthread  -lsqlite3  "\nconftest.c:14:57: error: use of undeclared identifier \'pthread_create\'\nint t(void) { void ((*volatile p)()); p = (void ((*)()))pthread_create; return !p; }\n                                                        ^\n1 error generated.\nchecked program was:\n/* begin */\n 1: #include "ruby.h"\n 2: \n 3: /*top*/\n 4: extern int t(void);\n 5: int main(int argc, char **argv)\n 6: {\n 7:   if (argc > 1000000) {\n 8:     int (* volatile tp)(void)=(int (*)(void))&t;\n 9:     printf("%d", (*tp)());\n10:   }\n11: \n12:   return !!argv[argc];\n13: }\n14: int t(void) { void ((*volatile p)()); p = (void ((*)()))pthread_create; return !p; }\n/* end */\n\nDYLD_FALLBACK_LIBRARY_PATH=.:/Users/jay/.frum/versions/3.1.0/lib "clang -o conftest -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/arm64-darwin21 -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/ruby/backward -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0 -I. -I/opt/homebrew/Cellar/sqlite/3.37.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef  -pipe  conftest.c  -L. -L/Users/jay/.frum/versions/3.1.0/lib -L. -fstack-protector-strong -L/usr/local/lib -L/opt/homebrew/Cellar/sqlite/3.37.2/lib     -lsqlite3 -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc -lpthread  -lsqlite3  "\nld: warning: ignoring file /opt/homebrew/Cellar/sqlite/3.37.2/lib/libsqlite3.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64\nld: warning: ignoring file /Users/jay/.frum/versions/3.1.0/lib/libruby.3.1-static.a, building for macOS-x86_64 but attempting to link with file built for macOS-arm64\nchecked program was:\n/* begin */\n 1: #include "ruby.h"\n 2: \n 3: /*top*/\n 4: extern int t(void);\n 5: int main(int argc, char **argv)\n 6: {\n 7:   if (argc > 1000000) {\n 8:     int (* volatile tp)(void)=(int (*)(void))&t;\n 9:     printf("%d", (*tp)());\n10:   }\n11: \n12:   return !!argv[argc];\n13: }\n14: extern void pthread_create();\n15: int t(void) { pthread_create(); return 0; }\n/* end */\n\n--------------------\n\nhave_library: checking for -ldl... -------------------- yes\n\nDYLD_FALLBACK_LIBRARY_PATH=.:/Users/jay/.frum/versions/3.1.0/lib "clang -o conftest -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/arm64-darwin21 -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/ruby/backward -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0 -I. -I/opt/homebrew/Cellar/sqlite/3.37.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef  -pipe  conftest.c  -L. -L/Users/jay/.frum/versions/3.1.0/lib -L. -fstack-protector-strong -L/usr/local/lib -L/opt/homebrew/Cellar/sqlite/3.37.2/lib    -lpthread  -lsqlite3 -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc -ldl -lpthread  -lsqlite3  "\nld: warning: ignoring file /opt/homebrew/Cellar/sqlite/3.37.2/lib/libsqlite3.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64\nld: warning: ignoring file /Users/jay/.frum/versions/3.1.0/lib/libruby.3.1-static.a, building for macOS-x86_64 but attempting to link with file built for macOS-arm64\nchecked program was:\n/* begin */\n 1: #include "ruby.h"\n 2: \n 3: /*top*/\n 4: extern int t(void);\n 5: int main(int argc, char **argv)\n 6: {\n 7:   if (argc > 1000000) {\n 8:     int (* volatile tp)(void)=(int (*)(void))&t;\n 9:     printf("%d", (*tp)());\n10:   }\n11: \n12:   return !!argv[argc];\n13: }\n14: \n15: int t(void) { ; return 0; }\n/* end */\n\n--------------------\n\nfind_library: checking for sqlite3_libversion_number() in -lsqlite3... -------------------- no\n\nDYLD_FALLBACK_LIBRARY_PATH=.:/Users/jay/.frum/versions/3.1.0/lib "clang -o conftest -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/arm64-darwin21 -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/ruby/backward -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0 -I. -I/opt/homebrew/Cellar/sqlite/3.37.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef  -pipe  conftest.c  -L. -L/Users/jay/.frum/versions/3.1.0/lib -L. -fstack-protector-strong -L/usr/local/lib -L/opt/homebrew/Cellar/sqlite/3.37.2/lib    -ldl -lpthread  -lsqlite3 -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc -lsqlite3 -ldl -lpthread  -lsqlite3  "\nconftest.c:14:57: error: use of undeclared identifier \'sqlite3_libversion_number\'\nint t(void) { void ((*volatile p)()); p = (void ((*)()))sqlite3_libversion_number; return !p; }\n                                                        ^\n1 error generated.\nchecked program was:\n/* begin */\n 1: #include "ruby.h"\n 2: \n 3: /*top*/\n 4: extern int t(void);\n 5: int main(int argc, char **argv)\n 6: {\n 7:   if (argc > 1000000) {\n 8:     int (* volatile tp)(void)=(int (*)(void))&t;\n 9:     printf("%d", (*tp)());\n10:   }\n11: \n12:   return !!argv[argc];\n13: }\n14: int t(void) { void ((*volatile p)()); p = (void ((*)()))sqlite3_libversion_number; return !p; }\n/* end */\n\nDYLD_FALLBACK_LIBRARY_PATH=.:/Users/jay/.frum/versions/3.1.0/lib "clang -o conftest -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/arm64-darwin21 -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0/ruby/backward -I/Users/jay/.frum/versions/3.1.0/include/ruby-3.1.0 -I. -I/opt/homebrew/Cellar/sqlite/3.37.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef  -pipe  conftest.c  -L. -L/Users/jay/.frum/versions/3.1.0/lib -L. -fstack-protector-strong -L/usr/local/lib -L/opt/homebrew/Cellar/sqlite/3.37.2/lib    -ldl -lpthread  -lsqlite3 -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc -lsqlite3 -ldl -lpthread  -lsqlite3  "\nld: warning: ignoring file /opt/homebrew/Cellar/sqlite/3.37.2/lib/libsqlite3.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64\nld: warning: ignoring file /Users/jay/.frum/versions/3.1.0/lib/libruby.3.1-static.a, building for macOS-x86_64 but attempting to link with file built for macOS-arm64\nUndefined symbols for architecture x86_64:\n  "_sqlite3_libversion_number", referenced from:\n      _t in conftest-593102.o\nld: symbol(s) not found for architecture x86_64\nclang: error: linker command failed with exit code 1 (use -v to see invocation)\nchecked program was:\n/* begin */\n 1: #include "ruby.h"\n 2: \n 3: /*top*/\n 4: extern int t(void);\n 5: int main(int argc, char **argv)\n 6: {\n 7:   if (argc > 1000000) {\n 8:     int (* volatile tp)(void)=(int (*)(void))&t;\n 9:     printf("%d", (*tp)());\n10:   }\n11: \n12:   return !!argv[argc];\n13: }\n14: extern void sqlite3_libversion_number();\n15: int t(void) { sqlite3_libversion_number(); return 0; }\n/* end */\n\n--------------------\n
Run Code Online (Sandbox Code Playgroud)\n

我通过 Homebrew 安装了 sqlite3,输出如下:

\n
sqlite: stable 3.37.2 (bottled) [keg-only]\nCommand-line interface for SQLite\nhttps://sqlite.org/index.html\n/opt/homebrew/Cellar/sqlite/3.37.2 (11 files, 4.3MB)\n  Poured from bottle on 2022-02-15 at 13:01:01\nFrom: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/sqlite.rb\nLicense: blessing\n==> Dependencies\nRequired: readline \xe2\x9c\x94\n==> Caveats\nsqlite is keg-only, which means it was not symlinked into /opt/homebrew,\nbecause macOS already provides this software and installing another version in\nparallel can cause all kinds of trouble.\n\nIf you need to have sqlite first in your PATH, run:\n  echo \'export PATH="/opt/homebrew/opt/sqlite/bin:$PATH"\' >> ~/.zshrc\n\nFor compilers to find sqlite you may need to set:\n  export LDFLAGS="-L/opt/homebrew/opt/sqlite/lib"\n  export CPPFLAGS="-I/opt/homebrew/opt/sqlite/include"\n\nFor pkg-config to find sqlite you may need to set:\n  export PKG_CONFIG_PATH="/opt/homebrew/opt/sqlite/lib/pkgconfig"\n
Run Code Online (Sandbox Code Playgroud)\n

根据 Homebrew 的建议,我进行了设置,bundle config build.sqlite3 --with-sqlite3-include=$(brew --prefix sqlite)/include --with-sqlite3-lib=$(brew --prefix sqlite)/lib但得到了似乎相同的结果。

\n

有人可以告诉我在这个设置下安装这个 gem 的正确方法是什么吗?非常感谢。

\n

小智 6

万一其他人遇到这个问题,我也遇到了类似的问题。我的开发环境设置为部分模拟和部分 ARM。

为了解决这个问题,我安装了两个不同版本的 Homebrew。其中一个版本适用于 M1 架构,它位于/opt/homebrew/. 我有一个运行在 x86 架构上的 Homebrew 版本,它位于/usr/local/Homebrew.

我的 x86 版本别名为ibrew,如下所示:

alias ibrew='arch --x86_64 /usr/local/Homebrew/bin/brew'
Run Code Online (Sandbox Code Playgroud)

(有关运行两个单独的 Homebrew 版本的更多信息,请参阅此答案。)

OP的捆绑配置命令对我有用,我只需brew换成ibrew

bundle config build.sqlite3 --with-sqlite3-include=$(brew --prefix sqlite)/include --with-sqlite3-lib=$(brew --prefix sqlite)/lib
Run Code Online (Sandbox Code Playgroud)