Failure to compile "unknown OSError exception code 22"

Hello PlatformIO community, this is my second post in a short time frame, sorry for that, but I need help once again. I’m trying to compile a simple empty loop program for a FeatherM4 Express using the Arduino header in C++, but it’s failing to compile and I don’t know why. Based on google searches the problem looks to be in python filepaths, but I don’t know where the error is or what’s causing it. I uninstalled and reinstalled python, and the issue persists.

My main.h:

#include <Arduino.h>

int main(){
while (1);

My platformio.ini:


platform = atmelsam

board = adafruit_feather_m4

framework = arduino

The error message:

Compiling .pio\build\adafruit_feather_m4\src\main.cpp.o
Compiling .pio\build\adafruit_feather_m4\FrameworkArduino\USB\USBCore.cpp.o
Compiling .pio\build\adafruit_feather_m4\FrameworkArduino\hooks.c.o
Compiling .pio\build\adafruit_feather_m4\FrameworkArduino\itoa.c.o
Compiling .pio\build\adafruit_feather_m4\FrameworkArduino\main.cpp.o
Compiling .pio\build\adafruit_feather_m4\FrameworkArduino\math_helper.c.o
Compiling .pio\build\adafruit_feather_m4\FrameworkArduino\new.cpp.o
Compiling .pio\build\adafruit_feather_m4\FrameworkArduino\pulse.c.o
unknown OSError exception code 22 - ‘C:\WINDOWS\System32\cmd.exe’: Invalid argument
*** [.pio\build\adafruit_feather_m4\FrameworkArduino\USB\USBCore.cpp.o] Error 127**

Any help would be greatly appreciated.

  1. .h is wrong for a file that is supposed to be compiled, use .cpp instead
  2. Do not overwrite the main() function when using the Arduino framework, it expects you to implement void setup() and void loop() instead, per example

The last person that had such problems here Espressif32 compiler problem - #20 by adriano63 said that this was being caused by RAV Antivirus. Any intrusive antivirus software installed?

No antivirus other than typical windows defender, and oops, yeah I don’t have much experience with arduino. I switched to a proper test program and received the same compile error.

You can try to have PlatformIO reinstall the toolchain by simply deleting the folders

  • C:\Users\<user>\.platformio\.cache
  • C:\Users\<user>\.platformio\packages\toolchain-gccarmnoneeabi

and building the project again.

If that still does not work, try executing the compiler on its own in a new command terminal (Windows + R → cmd.exe)

C:\Users\<user>\.platformio\packages\toolchain-gccarmnoneeabi\bin\arm-none-eabi-gcc --version

If that throws any fatal error, something’s fundamentally wrong or blocking execution.

Deleting the files didn’t resolve the error, but the version command executed fine. I’m probably going to try wiping my computer and see if that resolves the issue.

Wiping the computer worked, it’s compiling now. Not super helpful for people in the future, but I’m marking this as the solution in case people have the same error.