rake-compiler: Builds incompatible code on MacOS M1 / arm64 architecture

when building the C-extension, it builds x86_64 code on a arm64 CPU, which results in this error:

 require 'my_gem.bundle'
 LoadError: .... (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')

Is the CPU type is not correctly detected?

Is there a way to force the rake-compiler to only build code that exactly matches the CPU architecture?

About this issue

  • Original URL
  • State: open
  • Created 6 months ago
  • Comments: 25 (12 by maintainers)

Most upvoted comments

I couldn’t reproduce this with Homebrew’s Ruby:

$ PATH=$(brew --prefix ruby)/bin:$PATH ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
$ PATH=$(brew --prefix ruby)/bin:$PATH ruby -S rake compile
mkdir -p tmp/arm64-darwin22/smarter_csv/3.2.2
cd tmp/arm64-darwin22/smarter_csv/3.2.2
/opt/homebrew/opt/ruby/bin/ruby -I. ../../../../ext/smarter_csv/extconf.rb
creating Makefile
cd -
cd tmp/arm64-darwin22/smarter_csv/3.2.2
/usr/bin/make
compiling ../../../../ext/smarter_csv/smarter_csv.c
../../../../ext/smarter_csv/smarter_csv.c:42:8: warning: variable 'prev_char' set but not used [-Wunused-but-set-variable]
  char prev_char = '\0'; // Store the previous character for comparison against an escape character
       ^
1 warning generated.
linking shared-object smarter_csv/smarter_csv.bundle
ld: warning: -multiply_defined is obsolete
ld: warning: ignoring duplicate libraries: '-lruby.3.2'
cd -
mkdir -p tmp/arm64-darwin22/stage/lib/smarter_csv
/usr/bin/make install sitearchdir=../../../../lib/smarter_csv sitelibdir=../../../../lib/smarter_csv target_prefix=
/usr/bin/install -c -m 0755 smarter_csv.bundle ../../../../lib/smarter_csv
cp tmp/arm64-darwin22/smarter_csv/3.2.2/smarter_csv.bundle tmp/arm64-darwin22/stage/lib/smarter_csv/smarter_csv.bundle
$ file tmp/arm64-darwin22/smarter_csv/3.2.2/smarter_csv.bundle
tmp/arm64-darwin22/smarter_csv/3.2.2/smarter_csv.bundle: Mach-O 64-bit bundle arm64

Could you show full command line outputs like the above on your environment?