ruby-pg icon indicating copy to clipboard operation
ruby-pg copied to clipboard

"Missing compatible arch" for bundle on MacBook Air M1

Open me-kirill opened this issue 4 years ago • 11 comments

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.

me-kirill avatar Jan 15 '21 08:01 me-kirill

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.

adamlutz avatar Jan 25 '21 16:01 adamlutz

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?

connorshea avatar Mar 05 '21 02:03 connorshea

@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.

ged avatar Mar 09 '21 21:03 ged

@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 avatar Mar 09 '21 22:03 ged

@ged I've installed pg using "arch -x86_64" command. Now it's ok!

me-kirill avatar Mar 11 '21 09:03 me-kirill

@ged I've installed pg using "arch -x86_64" command. Now it's ok!

Full command?

daBee avatar Mar 11 '21 09:03 daBee

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.

marvdm avatar Mar 28 '21 08:03 marvdm

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"

jonathanhoskin avatar Apr 02 '21 23:04 jonathanhoskin

@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

jillisstada avatar Apr 12 '21 06:04 jillisstada

Thanks @jonathanhoskin and @marvdm. Reinstalling Postgres via ARM-based Homebrew and adding those flags to my .zshrc fixed my build issues perfectly 👍

jamogriff avatar May 04 '21 17:05 jamogriff

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!

connorshea avatar Jun 30 '22 01:06 connorshea