I am getting "bad CPU type in executable" compile error. Just installed IDE 2.0.3 on new MacBook Air running Monterey 12.5.1. When I run the same Arduino board on a different MacBook Air running Monterey 12.2, it runs fine - no compile errors. Ideas?
More from error message:
Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++: bad CPU type in executable
I'm not a Mac user and know nothing about it. but maybe the below gets you on the right track to solve it.
This relates to 32-bit vs 64-bit on the Mac; it used to be an issue in some of the 1.8.x versions of the IDE when Apple decided to only accept 64-bit applications and the IDE for Mac was only available in 32-bit.
Does this happen when you start the IDE or when you try to compile or upload? If it happens when you compile / upload, it indicates that the toolchain that is used is for the wrong architecture (32-bit if your OS is 64-bit). If this happens when you start the IDE, I have no idea.
Hi. Thank you so much! Yes, it's an M1 processor. I don't know if Rosetta 2 is installed, but I will try "softwareupdate --install-rosetta" command. Note - this never happened for me -> "If you have any x86 Intel apps available on the Apple Silicon Mac, simply launching the app will prompt the user to install Rosetta. Clicking āInstallā will then install the Rosetta 2 software onto the Mac." fwiw
I also would expect macOS to present that dialog offering the installation of Rosetta 2 if it wasn't already installed when Arduino IDE attempted to run the avr-g++ tool, which is built for x86-64 host architecture (and works perfectly already for many thousands of users with M1 Macs running Rosetta 2).
I have a question: when you downloaded Arduino IDE, did you use the "macOS Intel, 10.14: āMojaveā or newer, 64 bits" download link, or the "macOS Apple Silicon, 11: āBig Surā or newer, 64 bits" download link?:
Hey - thanks so much for your help. Yes, your idea occurred to me too. I was 95% sure I had picked the Apple Silicon one the first time I downloaded. So I tried again and when I downloaded the Apple Silicon one a second time I got the message that I had already downloaded that. I tried reinstalling it anyway (the Apple Silicon OS), but got the same "bad CPU type" when I tried to compile again...
This is expected. The native Apple Silicon build of Arduino IDE is only the Arduino IDE application itself. The avr-gcc toolchain is a completely separate component which is currently only available in x86-64 builds for macOS. Many such tools are used by Arduino IDE, so even if you are using the Apple Silicon build of Arduino IDE, Rosetta 2 is still required.
I didn't ask this question because I thought using the "macOS Apple Silicon, 11: āBig Surā or newer, 64 bits" variant of Arduino IDE might solve the problem. I asked it because I had a hypothesis (I don't have access to a Mac so I can't check) that, because it is executed by Arduino IDE as a subprocess, macOS does not present the Rosetta 2 installation dialog when running avr-g++. Arduino only created this Apple Silicon build of Arduino IDE 2.x last week. Previously, there was only an x86-64 build of Arduino IDE. So users with Apple Silicon-based machines that didn't already have Rosetta 2 would likely be presented with the Rosetta 2 installation dialog as soon as they started Arduino IDE. That may no longer be the case when using the Apple Silicon build of Arduino IDE, since Rosetta 2 is not required to run the Arduino IDE application itself (only the many x86-64 tools used by Arduino IDE).
Anyway, please make sure you have Rosetta 2 installed on your computer. If not, install it and then try compiling again.
Hey, your theory makes sense! I will try installing Rosetta 2 and will let you know. (May not be until the weekend though.). Thank you VERY much for your help.
You are welcome. I'm glad it is working now. I'll keep this situation in mind in order to more effectively provide assistance for future reports of this class of error message.
It might make sense to add an article about it to the Arduino Help Center if it turns out to be an emergent problem for the users with Apple Silicon machines.
I upgraded to 2.0.3 "macOS Intel, 10.14: āMojaveā or newer, 64 bits" after successfully running on 2,0.1 (what a great upgrade!) on Catalina 10.15.7 . I now receive the ābad CPU type in executableā. I have uninstalled and reinstalled 2.0.3. I have installed an earlier version of the IDE w/o success. Suggestions?
Hi @hashcalito. I'm going to ask you to post some additional information that might help us to identify the problem.
NOTE: These instructions will not solve the problem. They are only intended to gather more information which might provide a clue that eventually leads to a solution.
Please do this:
There should be an error notification at the bottom right corner of the Arduino IDE window. Click the "COPY ERROR MESSAGES" button on that notification.
Open a forum reply here by clicking the Reply button.
Click the </> icon on the post composer toolbar.
This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
Press Ctrl+V.
This will paste the compilation output into the code block.
Move the cursor outside of the code tags before you add any additional text to your reply.
Click the Reply button to post the output.
In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here:
Open a forum reply here by clicking the Reply button.
Click the "Upload" icon () on the post composer toolbar:
Select the .txt file you saved.
Click the Open button.
Click the Reply button to publish the post.
Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.
fork/exec /Users/me/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5/bin/avr-g++: bad CPU type in executable
Compilation error: fork/exec /Users/me/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5/bin/avr-g++: bad CPU type in executable
In order to get more information about the problem, now I'm going to ask you to post the output from a compilation with verbose output enabled in the Arduino IDE preferences.
Please do this:
Select File > Preferences from the Arduino IDE menus.
Check the box next to "Show verbose output during: ā compilation".
Click the OK button.
Select Sketch > Verify/Compile from the Arduino IDE menus.
Wait for the compilation to fail.
You will see a "Compilation error: ..." notification at the bottom right corner of the Arduino IDE window. Click the COPY ERROR MESSAGES button on that notification.
Open a forum reply here by clicking the Reply button.
Click the </> icon on the post composer toolbar.
This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
Press Ctrl+V.
This will paste the compilation output into the code block.
Move the cursor outside of the code tags before you add any additional text to your reply.
Click the Reply button to post the output.
In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here:
Open a forum reply here by clicking the Reply button.
Click the "Upload" icon () on the post composer toolbar:
Select the .txt file you saved.
Click the Open button.
Click the Reply button to publish the post.
Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.
Using board 'digispark-tiny' from platform in folder: /Users/hashcalito/Library/Arduino15/packages/digistump/hardware/avr/1.6.7
Using core 'tiny' from platform in folder: /Users/hashcalito/Library/Arduino15/packages/digistump/hardware/avr/1.6.7
Detecting libraries used...
/Users/hashcalito/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=16500000L -DARDUINO=10607 -DARDUINO_AVR_DIGISPARK -DARDUINO_ARCH_AVR -I/Users/hashcalito/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/cores/tiny -I/Users/hashcalito/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/variants/digispark /private/var/folders/bh/k8472yqs0qx3xyhvkwb_bzr40000gn/T/arduino-sketch-BB91CEF8D2EC002FC3B7DBC40DEA5381/sketch/Keyboard.ino.cpp -o /dev/null
fork/exec /Users/hashcalito/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5/bin/avr-g++: bad CPU type in executable
Compilation error: fork/exec /Users/hashcalito/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5/bin/avr-g++: bad CPU type in executable
Unfortunately the Digispark boards platform from the manufacturer Digistump has not been maintained for many years. This causes it to use an ancient version of the avr-gcc compiler toolchain from before the time when Arduino started producing 64-bit builds of the tool for macOS. So in this case the error has nothing to do with the Apple Silicon CPU on your computer but is instead that modern versions of macOS are not compatible with 32-bit applications.
Fortunately the Arduino community comes through as always and there is an excellent actively maintained 3rd party boards platform named ATTinyCore that has support for the Digispark board and a modern toolchain. The installation instructions for ATTinyCore are here:
Make sure to use the "Boards Manager Installation" instructions on that page. The "Manual Installation" are only for beta testers so you don't need to follow those.