我正在遵循一些包含此步骤的设置说明:
ARCHFLAGS="-arch x86_64" gem install pg -v 1.2.3
问题似乎与我正在运行带有 M1 芯片的 MacBookPro 相关,根据 this SO thread
预期结果大概是成功安装了 pg gem(版本 1.2.3)
相反,我看到了一些错误,我认为这些错误与英特尔和苹果芯片之间使用的不同文件路径有关。
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /Users/JRBOBDOBBS/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/pg-1.2.3/ext
/Users/JRBOBDOBBS/.rbenv/versions/3.2.2/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /Applications/Postgres.app/Contents/Versions/latest/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... yes
checking for PQsetSingleRowMode()... yes
checking for PQconninfo()... yes
checking for PQsslAttribute()... yes
checking for PQresultVerboseErrorMessage()... yes
checking for PQencryptPasswordConn()... yes
checking for PQresultMemorySize()... yes
checking for timegm()... yes
checking for rb_gc_adjust_memory_usage()... yes
checking for unistd.h... yes
checking for inttypes.h... yes
checking for C99 variable length arrays... yes
creating extconf.h
creating Makefile
current directory: /Users/JRBOBDOBBS/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/pg-1.2.3/ext
make DESTDIR\= sitearchdir\=./.gem.20230720-5310-17fm3z sitelibdir\=./.gem.20230720-5310-17fm3z clean
current directory: /Users/JRBOBDOBBS/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/pg-1.2.3/ext
make DESTDIR\= sitearchdir\=./.gem.20230720-5310-17fm3z sitelibdir\=./.gem.20230720-5310-17fm3z
compiling gvl_wrappers.c
In file included from gvl_wrappers.c:6:
In file included from ./pg.h:61:
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
^
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
^
2 warnings generated.
compiling pg.c
In file included from pg.c:49:
In file included from ./pg.h:61:
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
^
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
^
2 warnings generated.
compiling pg_binary_decoder.c
In file included from pg_binary_decoder.c:8:
In file included from ./pg.h:61:
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
^
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
^
2 warnings generated.
compiling pg_binary_encoder.c
In file included from pg_binary_encoder.c:7:
In file included from ./pg.h:61:
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
^
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
^
2 warnings generated.
compiling pg_coder.c
In file included from pg_coder.c:6:
In file included from ./pg.h:61:
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
^
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
^
pg_coder.c:216:34: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
res = this->dec_func(this, val, RSTRING_LEN(argv[0]), tuple, field, ENCODING_GET(argv[0]));
~~~~ ^~~~~~~~~~~~~~~~~~~~
/Users/JRBOBDOBBS/.rbenv/versions/3.2.2/include/ruby-3.2.0/ruby/internal/core/rstring.h:52:27: note: expanded from macro 'RSTRING_LEN'
#define RSTRING_LEN RSTRING_LEN
^
3 warnings generated.
compiling pg_connection.c
In file included from pg_connection.c:7:
In file included from ./pg.h:61:
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
^
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
^
pg_connection.c:679:17: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return INT2NUM(atol(port));
~~~~~~~ ^~~~~~~~~~
3 warnings generated.
compiling pg_copy_coder.c
In file included from pg_copy_coder.c:6:
In file included from ./pg.h:61:
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
^
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
^
pg_copy_coder.c:228:15: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
strlen = RSTRING_LEN(subint);
~ ^~~~~~~~~~~~~~~~~~~
/Users/JRBOBDOBBS/.rbenv/versions/3.2.2/include/ruby-3.2.0/ruby/internal/core/rstring.h:52:27: note: expanded from macro 'RSTRING_LEN'
#define RSTRING_LEN RSTRING_LEN
^
pg_copy_coder.c:534:23: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
input_len = end_ptr - start_ptr;
~ ~~~~~~~~^~~~~~~~~~~
4 warnings generated.
compiling pg_errors.c
In file included from pg_errors.c:6:
In file included from ./pg.h:61:
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
^
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
^
2 warnings generated.
compiling pg_record_coder.c
In file included from pg_record_coder.c:6:
In file included from ./pg.h:61:
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
^
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
^
pg_record_coder.c:196:15: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
strlen = RSTRING_LEN(subint);
~ ^~~~~~~~~~~~~~~~~~~
/Users/JRBOBDOBBS/.rbenv/versions/3.2.2/include/ruby-3.2.0/ruby/internal/core/rstring.h:52:27: note: expanded from macro 'RSTRING_LEN'
#define RSTRING_LEN RSTRING_LEN
^
3 warnings generated.
compiling pg_result.c
In file included from pg_result.c:7:
In file included from ./pg.h:61:
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
^
/Applications/Postgres.app/Contents/Versions/15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
^
pg_result.c:1006:17: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return INT2NUM(n);
~~~~~~~ ^
pg_result.c:1590:58: error: use of undeclared identifier 'rb_cData'
rb_cPGresult = rb_define_class_under( rb_mPG, "Result", rb_cData );
^
3 warnings and 1 error generated.
make: *** [pg_result.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/JRBOBDOBBS/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/pg-1.2.3 for inspection.
Results logged to /Users/JRBOBDOBBS/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/extensions/arm64-darwin-20/3.2.0/pg-1.2.3/gem_make.out
ARCHFLAGS="-arch $(uname -m)" gem install pg -v 1.2.3
我认为这是一个非常巧妙的即兴创作;唉,没有骰子
我考虑过放弃
ARCHFLAGS
位,因为归根结底,这不就是简单地尝试安装 1.2.3 版本的 pg 吗?
在配备 M1 芯片的 MacBookPro 上使用
ARCHFLAGS
变量的正确、明确的命令是什么?
或者也许更切题:
我还需要对 ARCHFLAGS 变量大惊小怪吗?
我找到了类似问题的解决方案并完成了那里的步骤:
brew install libpq
export PATH="/opt/homebrew/opt/libpq/bin:$PATH
gem install pg
安装成功,但那是 pg -v 1.5.3 (如果我使用 -v 1.2.3 真的很重要吗?)
拥有
libpq
是执行此操作的正确方法,并且没有 - 没有理由使用低于最新的 pg
除非您有特定原因这样做(例如旧/遗留项目)。
另外,正如我认为您意识到的那样,根据您的
ARCHFLAGS="-arch $(uname -m)"
示例(非常漂亮),对 arm64 芯片(即 Mac M1/M2)使用 x86 标志永远不会起作用。