"Missing compatible arch" for bundle on MacBook Air M1
I'm trying to run my app on MacBook Air m1 and see following issue:
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require': dlopen(/Library/Ruby/Gems/2.6.0/gems/pg-1.2.3/lib/pg_ext.bundle, 0x0009): missing compatible arch in /Library/Ruby/Gems/2.6.0/gems/pg-1.2.3/lib/pg_ext.bundle - /Library/Ruby/Gems/2.6.0/gems/pg-1.2.3/lib/pg_ext.bundle (LoadError)
from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `block in require'
from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:299:in `load_dependency'
from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require'
from /Library/Ruby/Gems/2.6.0/gems/pg-1.2.3/lib/pg.rb:5:in `<top (required)>'
Postgres was installed via homebrew.
Also running into the same problem.
FWIW, I posted a work-around for me that installs homebrew, ruby, rbenv, and all gems as intel x86 here on stackoverflow to get around the problem temporarily.
Does anyone have a better solution than reinstalling homebrew, ruby, etc under ARM? Or are we stuck with that until someone gets the gem compatible with ARM?
@benone Did you compile pg on the same machine you're running it on? I have had this problem deploying to an ARM-based machine after compiling it on an x86 one. I don't know why the machine would compile a library in an architecture other than its own. I don't have access to an M1-based Mac, so I can't test this myself unfortunately.
@adamlutz The error in that Stackoverflow thread seems to be caused by the libpq that PostgresApp includes not being compiled for ARM. All the libraries in a particular runtime (I think) have to be built with the same architecture. Your temporary solution seems to confirm that. Any thoughts?
@ged I've installed pg using "arch -x86_64" command. Now it's ok!
@ged I've installed pg using "arch -x86_64" command. Now it's ok!
Full command?
Does anyone have a better solution than reinstalling homebrew, ruby, etc under ARM? Or are we stuck with that until someone gets the gem compatible with ARM?
Switching from Postgres.app to Homebrew installation of Postgres did it for me. Apparently, Postgres.app runs on Rosetta.
NOTE: You may need to set the following env variables before installing the gem — this may not be necessary at all but it worked. Replace 12 with your version:
export LDFLAGS="-L/opt/homebrew/opt/postgresql@12/lib"
export CPPFLAGS="-I/opt/homebrew/opt/postgresql@12/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/postgresql@12/lib/pkgconfig"
P.S. I wrote this right after the installation went through but I am yet to run and test the whole Rails app.
Thanks @marvdm - the instructions above are very helpful.
In addition to those three, I also needed to add the following:
export PATH="${HOMEBREW_PREFIX}/opt/postgresql@12/bin:$PATH"
... so my .bash_profile now contains these:
export PATH="${HOMEBREW_PREFIX}/opt/postgresql@12/bin:$PATH"
export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/postgresql@12/lib"
export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/postgresql@12/include"
export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/postgresql@12/lib/pkgconfig"
@ged I've installed pg using "arch -x86_64" command. Now it's ok!
Full command?
arch -arch x86_64 gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/13/bin/pg_config
Thanks @jonathanhoskin and @marvdm. Reinstalling Postgres via ARM-based Homebrew and adding those flags to my .zshrc fixed my build issues perfectly 👍
Should note that I think it needs to be Postgres 14+ if you install via ARM-based Homebrew, it doesn't seem to work on older Postgres versions?
EDIT: actually it may have been that I made a mistake in my .zshrc and left it on @14 even after I installed 12!