I'm following some setup instructions that has this step:
ARCHFLAGS="-arch x86_64" gem install pg -v 1.2.3
problem appears to be related to the fact that I'm running a MacBookPro with an M1 chip, per this SO thread
the expected result is presumably a successfully installed pg gem (version 1.2.3)
Instead, I'm seeing errors that I believe are related to the different file paths that are used between Intel and Apple silicon.
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
Which I thought was a pretty slick improvisation; alas, no dice
I considered just foregoing the ARCHFLAGS
bit, because at the end of the day, isn't this simply attempting to install the 1.2.3 version of pg?
What's the proper, unambiguous command for using the ARCHFLAGS
variable on a MacBookPro with M1 chip?
Or maybe more to the point:
Do I even need to fuss with that ARCHFLAGS variable?
I found this solution to a similar issue and went through the steps there:
brew install libpq
export PATH="/opt/homebrew/opt/libpq/bin:$PATH
gem install pg
and it installed succesfully, but that was pg -v 1.5.3 (does it really matter if I use -v 1.2.3?)
Having libpq
is the right way to do this, and no - no reason to use less than the latest pg
unless you have a specific reason to do so (eg. an old/legacy project).
Also, as I think you realized, based on your ARCHFLAGS="-arch $(uname -m)"
example (which is very nifty), using the x86 flags for an arm64 chip (ie. Mac M1/M2) is never going to work.