24" mac, M1: bad CPU type in executable

Running IDE 2.0.3 on 24" mac, Apple M1, Ventura 13.0.
Downlaoded: macOS Apple Silicon, 11:"Big Sur" or newer, 64 bits.
I have Arduino UNO selected.

No ports selected. No hardware connected.

When I verify blinky I get:

bad CPU type in executable

Full message:


Using board 'uno' from platform in folder: /Users/john/Library/Arduino15/packages/arduino/hardware/avr/1.8.6

Using core 'arduino' from platform in folder: /Users/john/Library/Arduino15/packages/arduino/hardware/avr/1.8.6

Detecting libraries used...

/Users/john/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/Users/john/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino -I/Users/john/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/variants/standard /private/var/folders/1g/_mb7zw6s75s5fv_xk6gl5fzc0000gn/T/arduino-sketch-6BE808163E7E6D5308FD02D4A989479A/sketch/blinky.ino.cpp -o /dev/null

fork/exec /Users/john/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++: bad CPU type in executable

Compilation error: fork/exec /Users/john/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++: bad CPU type in executable


The only thing I have found to try that applies to me is deleted:

/Users/john/Library/Arduino15/packages/builtin/tools/ctags/5.8-arduino11

with the same results.

Hi @boolrules. This error can be caused by not having Apple's Rosetta 2 software installed. Even though your Arduino IDE 2.x installation is a native Apple Silicon build, the tools used by Arduino IDE are still built for x86 host architecture. That is no problem as long as you have Rosetta 2 installed because it allows x86 applications to run perfectly on the Apple Silicon machines.

Normally when you start an x86 application macOS presents a dialog explaining that you need to install Rosetta 2:


However, I'm not sure whether that happens in this case where the x86 application is a tool running in a subprocess. This is a fairly new situation because we published the first native Apple Silicon build of Arduino IDE only a few weeks ago. I'll investigate the situation (unfortunately I already have Rosetta 2 installed on my M1 machine).

Please try manually installing Rosetta 2. I'll provide instructions:

  1. Open your Applications folder in Finder.
  2. Open the Utilities folder.
  3. Double-click on "Terminal".
  4. Type the following command in the Terminal window:
    softwareupdate --install-rosetta
    
  5. Accept the license agreement.
  6. Wait for the installation to finish.

Now tray compiling your sketch again in Arduino IDE. Hopefully this time that "bad CPU type in executable" error will not occur and everything will work correctly.

Thank you for your very thorough reply.
See what happens when I assume stuff? Was hoping for a native build. I'll have to think about what I want to do here.
Thanks again. Much appreciated.

You are welcome.

I'm not sure what the prospects will be of getting native Apple Silicon builds of the various helper tools and toolchain. It is unfortunately quite difficult to produce these builds. In the case of Arduino IDE, the payoff of better application performance makes the effort worthwhile, but I'm not sure there is such a significant benefit when it comes to some of these other tools, and the existing x86 builds are already working fine (even if maybe less efficiently) via Rosetta 2. Even if Arduino makes the native Apple Silicon builds of the tools we distribute directly, it is unlikely all the 3rd party platform maintainers will also do the same for their toolchains, so the problem will persist regardless.

At the very least, we plan to produce official documentation about the cause of this "bad CPU type in executable" error and the fix for it.

Please let us know if you have any other questions, concerns, or problems. I would also be interested to hear what you decide in the end. As I mentioned before, this is new territory for the project (and even for me personally since I bought my first M1 machine only a few weeks ago) so I am very interested in learning more and getting any feedback from the affected users.

Thank you... this worked perfectly for me!

You are welcome. I'm glad if I was able to be of assistance.

Regards,
Per

Hi. M1Pro Ventura 13.2.1 user here. I've got the "avr-g++: bad CPU type in executable" error as well, and I can't shake it. Attempting the terminal-based Rosetta solution results in "Installing Rosetta 2 on this system is not supported. "

Next steps?

Hi @wugmump.

I did some research and found quite a few reports of macOS users (in general, nothing Arduin-specific) getting this error when running the softwareupdate --install-rosetta command. Unfortunately most of those reports did not have a resolution.

I think you might get this error from running the command on a Mac with an Intel processor, but you mentioned "M1Pro", which I assume means your Mac has an M1 processor?

The only resolution I found in this case:

https://www.reddit.com/r/MacOS/comments/qobjos/rosetta_broken_removed_on_monterey/

issue vanished after a restart

So try restarting your computer and then running the softwareupdate --install-rosetta command again. Hopefully it will succeed this time.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.