搭载M2芯片的MacBookPro上Gem构建失败求助
gio2 gem编译失败(arm64架构)求助
设备环境信息
OS: Ventura 13.2.1 M2-Max Silicon Ruby 3.1.0 Rails 7.0.2
已完成的全新安装流程
安装homebrew 通过homebrew安装rbenv 通过rbenv安装ruby 3.1.0 安装rails 7.0.2 gem包 通过homebrew安装MySQL
仅迁移了源代码文件,未从旧设备转移其他内容。
执行命令及报错
执行命令:
bundle run
报错内容:
Installing gio2 3.5.1 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension. .......... ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [gio2.bundle] Error 1 make failed, exit code 2 An error occurred while installing gio2 (3.5.1), and Bundler cannot continue. In Gemfile: poppler was resolved to 3.5.1, which depends on cairo-gobject Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
解决思路
- 安装gio2依赖的底层系统库:
brew install glib cairo gobject-introspection - 设置环境变量,确保gem编译时能找到arm64架构的库路径:
export LDFLAGS="-L/opt/homebrew/lib" export CPPFLAGS="-I/opt/homebrew/include" export PKG_CONFIG_PATH="/opt/homebrew/lib/pkgconfig" - 重新执行依赖安装:
bundle install - 若仍失败,重新编译arm64版本的Ruby:
CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl)" rbenv install 3.1.0 - 检查Homebrew架构:M2设备上Homebrew默认路径应为
/opt/homebrew,若你的在/usr/local,说明是x86版本,需重新安装arm64版Homebrew
内容的提问来源于stack exchange,提问作者EastsideDev
相关产品推荐
相关产品推荐

