我一直在尝试在我的运行Big Sur的电脑上安装一个rails项目(Macbook Pro 2020,带M1)。
我已经安装了PostgresApp。
在运行bundle install时,它无法构建pg gem,所以我尝试手动安装gem (通过对gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/10/bin/pg_config执行gem install pg - to )。
我收到一个错误,说:
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***检查错误日志时,我看到:
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 */你知道怎么解决这个问题吗?
发布于 2021-12-11 16:37:25
对于那些只想安装pg gem而不关心PostgresApp的人来说,在M1上修复pg的关键是确保libpq的存在。这些步骤允许我在我的M1 mac上安装pg gem,而不需要使用x86版本或构建标志:
brew install libpq
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
gem install pg发布于 2021-01-25 23:58:32
我在使用M1 + ruby pg gem时遇到了同样的问题。问题是我的系统上混合了ARM + x86二进制文件,而pg目前显然只能用x86编译。作为参考,在其github库中报告了新的问题,所以希望它能很快得到解决,here
我的工作是:
中删除.gem + .rbenv目录
$ arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"的身份安装rbenv
$ arch -x86_64 brew install rbenv
$ arch -x86_64 rbenv install 2.7.2$ bundle config build.pg- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config上享受ruby
$ bundle install
$ rails s发布于 2021-11-05 08:42:46
在使用brew PostgreSQL时遇到了同样的问题,但我在macOS M1(12蒙特利)上使用Ruby2.7成功地安装了pg gem,我同时安装了x86和arm64 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)然后我就可以安装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但是Ruby2.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)更新2021-11-06
在Ruby2.6上也成功安装了pg。
# build Postgresql from source, as
# Error: postgresql: no bottle available!
# You can try to install from source with:
# brew install --build-from-source postgresql
brow install --build-from-source postgresql的pg gem
gem install pg -v 1.2.3 -- --with-pg_config=/usr/local/Cellar/postgresql/13.3/bin/pg_config --with-pq-dir=/usr/local/Cellar/libpq/13.3 https://stackoverflow.com/questions/65810224
复制相似问题