简体   繁体   English

ARM64架构(M1芯片):无法安装pg gem(使用PostgresApp)

[英]ARM64 architecture (M1 chip): Cannot install pg gem (using PostgresApp)

I've been trying to install a rails project on my computer (Macbook Pro 2020 with M1) running Big Sur.我一直在尝试在运行 Big Sur 的计算机(带有 M1 的 Macbook Pro 2020)上安装 rails 项目。

I have the PostgresApp installed.我安装了 PostgresApp。

When running bundle install it fails to build the pg gem so I tried to install the gem manually (by doing gem install pg - tried also with gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/10/bin/pg_config ).运行bundle install时,无法构建pg gem,所以我尝试手动安装 gem(通过执行gem install pg - 也尝试使用gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/10/bin/pg_config )。

I get an error saying:我收到一条错误消息:

ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.

Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***

When checking the error logs I see:检查错误日志时,我看到:

have_library: checking for PQconnectdb() in -lpq... -------------------- no

ld: warning: ignoring file /Applications/Postgres.app/Contents/Versions/13/lib/libpq.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
  "_PQconnectdb", referenced from:
      _t in conftest-db479f.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
 1: #include "ruby.h"
 2:
 3: #include <libpq-fe.h>
 4:
 5: /*top*/
 6: extern int t(void);
 7: int main(int argc, char **argv)
 8: {
 9:   if (argc > 1000000) {
10:     printf("%p", &t);
11:   }
12:
13:   return 0;
14: }
15: int t(void) { void ((*volatile p)()); p = (void ((*)()))PQconnectdb; return !p; }
/* end */

Any idea how to solve this?知道如何解决这个问题吗?

I ran into the same problem with M1 + the ruby pg gem.我在 M1 + ruby pg gem 上遇到了同样的问题。 The problem was that I had a mix of ARM + x86 binaries on my system, and pg apparently can only be compiled with x86 at present.问题是我的系统上混合了 ARM + x86 二进制文件,而pg目前显然只能用 x86 编译。 As FYI, there are new issues reported in its github repo, so hopefully it'll be solved soon here仅供参考,在其 github 存储库中报告了新问题,因此希望它会很快在这里得到解决

My work around:我的工作:

  1. uninstall ARM based homebrew + rbenv and remove your .gem + .rbenv directories from your home dir ( homebrew uninstall instructions )卸载基于 ARM 的自制软件 + rbenv 并从主目录中删除.gem + .rbenv目录(自制软件卸载说明

  2. re-install homebrew as x86 intel-based重新安装自制软件为 x86 intel-based

$ arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  1. install rbenv as x86 (or whatever your preferred ruby version manager)将 rbenv 安装为 x86 (或任何您喜欢的 ruby 版本管理器)
$ arch -x86_64 brew install rbenv
$ arch -x86_64 rbenv install 2.7.2
  1. (optional) for postgres.app, you can pre-configure where pg-config lives so you don't have to run the manual gem install when it chokes. (可选)对于 postgres.app,您可以预先配置 pg-config 所在的位置,这样您就不必在它阻塞时运行手动 gem 安装。 eg例如
$ bundle config build.pg- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
  1. re-bundle your project and enjoy ruby on rosetta 2 (for now)重新捆绑您的项目并在 Rosetta 2 上享受 ruby(目前)
$ bundle install
$ rails s

I installed pg gem successfully with Ruby 2.7 on macOS M1(12 Monterey), I have both x86 and arm64 brew installed.我在 macOS M1(12 Monterey)上使用 Ruby 2.7 成功安装了 pg gem,我同时安装了 x86 和 arm64 brew。 Since pg must be compiled with x86 libpq, so I installed libpq with x86 brew由于pg必须用x86 libpq编译,所以我用x86 brew安装了libpq


❯ which brow
brow: aliased to arch --x86_64 /usr/local/Homebrew/bin/brew

❯ brow install libpq

❯ brew install PostgreSQL # Install arm64 PostgreSQL 
❯ brew services start postgresql
❯ ps -ef | grep postgresql
  501 23655     1   0  2:29PM ??         0:00.10 /opt/homebrew/opt/postgresql/bin/postgres -D /opt/homebrew/var/postgres

❯ which brew
/opt/homebrew/bin/brew
❯ brew -v
Homebrew 3.3.2-50-geca16a2
Homebrew/homebrew-core (git revision ec99d74792c; last commit 2021-11-05)
Homebrew/homebrew-cask (git revision 2ab51af9c3; last commit 2021-11-05)

Then I can install the pg gem然后我可以安装 pg gem

❯ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]

❯ gem install pg -v 1.2.3 -- --with-pq-dir=/usr/local/Cellar/libpq/13.3
Building native extensions with: '--with-pq-dir=/usr/local/Cellar/libpq/13.3'
This could take a while...
Successfully installed pg-1.2.3
Parsing documentation for pg-1.2.3
Done installing documentation for pg after 0 seconds

But failed with Ruby 2.6, I don't known why但是 Ruby 2.6 失败了,我不知道为什么

gem install pg -v 1.2.3 -- --with-pq-dir=/usr/local/Cellar/libpq/13.3
Building native extensions with: '--with-pq-dir=/usr/local/Cellar/libpq/13.3'
This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    current directory: /Users/felix/.rvm/gems/ruby-2.6.6/gems/pg-1.2.3/ext
/Users/felix/.rvm/rubies/ruby-2.6.6/bin/ruby -I /Users/felix/.rvm/rubies/ruby-2.6.6/lib/ruby/site_ruby/2.6.0 -r ./siteconf20211105-41969-1oxcuyy.rb extconf.rb --with-pq-dir\=/usr/local/Cellar/libpq/13.3
checking for pg_config... yes
Using config values from /opt/homebrew/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)

For those who are just trying to install the pg gem and don't care about PostgresApp, the key to fixing pg on the M1 is ensuring the existence of the libpq .对于那些只是尝试安装 pg gem 并且不关心 PostgresApp 的人,在 M1 上修复 pg 的关键是确保libpq的存在。 These steps allowed me to get the pg gem install on my M1 mac without resorting to using x86 version or build flags:这些步骤允许我在我的 M1 mac 上安装 pg gem,而无需使用 x86 版本或构建标志:

brew install libpq
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
gem install pg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MacOs (M1 Arm64) 无法加载 Nokogiri - 使用系统默认值 Ruby - MacOs (M1 Arm64) unable to load Nokogiri - Using system default Ruby 如何在 mac mini m1 上安装 gem pg? - How to install gem pg on mac mini m1? (mach-o 文件,但在运行 rake db:create 时是苹果 M1 芯片上的不兼容架构(具有“x86_64”,需要“arm64e”)) - (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')) on apple M1 chip when running rake db:create 努力在OSX Lion上安装pg gem-“缺少文件x86_64所需的体系结构x86_64” - Struggling to install pg gem on OSX Lion - “missing required architecture x86_64 in file for architecture x86_64” 如何在M1芯片上成功安装ffi 1.9.25 - How to install ffi 1.9.25 successfully on M1 Chip 无法安装gem pg -v&#39;0.15.1&#39; - Cannot install the gem pg -v '0.15.1' 无法安装pg gem,请在-lpq中检查PQconnectdb()...否 - cannot install pg gem, checking for PQconnectdb() in -lpq… no 无法在 Mac OSX 上安装 PG gem - Cannot install PG gem on Mac OSX 错误:无法构建 gem 本机扩展。 M1 芯片未找到potracelib.h - ERROR: Failed to build gem native extension. potracelib.h not found with M1 chip rmagick gem 安装问题未声明的标识符 &#39;IsGrayImage&#39; Macbook M1 - rmagick gem install problem undeclared identifier 'IsGrayImage' Macbook M1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM