PlatformIO is Broken for any esp32!

hello this is my first post here and i have a really strange bug.

I don’t understand why but my platformIO is completely broken and i can’t compile anything using the toolchain-xtensa32 . The compilation still works fine for Arduino cards.
When i try to create an empty project for any esp32 i get random empty files created with strange names like @ , ؄ or pX . i also get the error

unable to resolve configuration with the compilerPath
"C:/Users/username/.platformio/packages/toolchain-xtensa32/bin/xtensa-esp32-elf-gcc.exe".
Using "cl.exe" instead

and when i check the folder i see that the file xtensa-esp32-elf-gcc.exe is actually 0 bytes. I tried to reinstall the toolchain multiple times and this file will always eventually end up being 0 bytes. Even when i have this file actually existing it still won’t compile a simple hello world with Serial.println() , the error i usually get are things like

c:\users\username\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\8.4.0\xtensa-esp32-elf\no-rtti\bits\gthr-default.h:
In function 'int __gthread_mutex_timedlock(__gthread_mutex_t*, const __gthread_time_t*)':

c:\users\username\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\8.4.0\xtensa-esp32-elf\no-rtti\bits\gthr-default.h:781:12: 
error: 'pthread_mutex_timedlock' was not declared in this scope
     return __gthrw_(pthread_mutex_timedlock) (__mutex, __abs_timeout);
            ^~~~~~~~
C:\Users\username\.platformio\packages\framework-arduinoespressif32\cores\esp32\StreamString.cpp:26:8: error: 'StreamString' has not been declared size_t StreamString::write(const uint8_t *data, size_t size) {
        ^~~~~~~~~~~~
C:\Users\username\.platformio\packages\framework-arduinoespressif32\cores\esp32\StreamString.cpp: In function 'size_t write(const uint8_t*, size_t)':

C:\Users\username\.platformio\packages\framework-arduinoespressif32\cores\esp32\StreamString.cpp:28:37: error: 'length' was not declared in this scope
         const unsigned int newlen = length() + size;
ect...

i also tried to install manually another version of the toolchain-xtensa (the 8.4.0) but the xtensa-esp32-elf-gcc.exe still end up being turned into a 0 byte file. I don’t have any antivirus other than the default windows one.

This problem even happen on older project that were compiling perfectly fine before

i think that the zeroing of the file happens when i open a project folder and platformIO “load tasks” or “rebuild intelisens index”

if anyone has any idea of what’s happening and how i could make platformIO work again i would be very grateful.

ps : english is not my first language, sorry if it’s hard to understand something

Remove this folder + C:\Users\<user>\.platformio\.cache and rebuild the project.

Remove this folder + C:\Users\<user>\.platformio\.cache and rebuild the project.

i still have errors like

c:\users\arthu\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\sys-include\stdlib.h: At global scope:
c:\users\arthu\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\sys-include\stdlib.h:94:44: error: expected initializer before '__result_use_check'
 void *calloc(size_t, size_t) __malloc_like __result_use_check
                                            ^~~~~~~~~~~~~~~~~~
c:\users\arthu\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\sys-include\stdlib.h:112:36: error: expected initializer before '__result_use_check'
 void *malloc(size_t) __malloc_like __result_use_check __alloc_size(1) _NOTHROW;
                                    ^~~~~~~~~~~~~~~~~~

o_O. Remove all folders in C:\Users\<user>\.platformio\packages + C:\Users\<user>\.platformio\platforms (+.cache if it has filled up again) so that all packages are cleanly redownloaded.

If this still does not work, post your full platformio.ini and minimal test code.

2 Likes

Thank you a lot, it fixed all the errors and now all of my esp32 projects works again.

There is still something i don’t understand, i’ve already tried to erase the whole C:\Users\<user>\.platformio folder before asking and it didn’t solve the issue. Any idea for why just deleting the content of those folders solved my issue but deleting the whole .platformio didn’t work?

I am having this exact same issue, deleting the .platformio folder did not work. Even the Platformio Example projects all do the same thing! My projects also fill up with junk files, and it’s not the code in my projects - when i create a fresh project, it does the same thing. I upgraded to --dev to try and fix it - still the same thing. I uninstalled platformio(correctly) - same thing. I even uninstalled VSCode - same thing. I am at a loss rn.

I deleted the requested folders, instead of the whole .platformio folder - and i was able to get a single example project to build. So, i created a new project - and then it promptly corrupted my entire platformio installation and gave me the same errors. I re-opened the Example project, to check, and it no longer builds. No changes to it all from my end. When i try to build, windows gives me a pop-up saying “This application can not run on your computer” and then the terminal states that Access was Denied while compiling the Arduino cpp files. I honestly have no idea what is going on. It is very annoying.

This is the Arduino Blink example project from the Espressif32 Platform. All i did was open it and i get all of these generated junk files. This is happening to all of my platformio projects, and only in platformio specific projects.

rocessing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.5.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 3.10006.210326 (1.0.6)
 - tool-esptoolpy 1.30100.210531 (3.1.0)
 - toolchain-xtensa32 2.50200.97 (5.2.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 28 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\esp32dev\src\main.cpp.o
Generating partitions .pio\build\esp32dev\partitions.bin
Archiving .pio\build\esp32dev\libFrameworkArduinoVariant.a
Indexing .pio\build\esp32dev\libFrameworkArduinoVariant.a
Compiling .pio\build\esp32dev\FrameworkArduino\Esp.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\FunctionalInterrupt.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\HardwareSerial.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\IPAddress.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\IPv6Address.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\MD5Builder.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\Print.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\Stream.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\StreamString.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\WMath.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\WString.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\base64.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\cbuf.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-adc.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-bt.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-cpu.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-dac.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-gpio.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-i2c.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-ledc.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-log.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-matrix.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-misc.c.o
Access is denied.
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-psram.c.o
*** [.pio\build\esp32dev\FrameworkArduino\esp32-hal-i2c.c.o] Error 1
Access is denied.
*** [.pio\build\esp32dev\FrameworkArduino\esp32-hal-ledc.c.o] Error 1
Access is denied.
Access is denied.
*** [.pio\build\esp32dev\FrameworkArduino\esp32-hal-log.c.o] Error 1
*** [.pio\build\esp32dev\FrameworkArduino\esp32-hal-matrix.c.o] Error 1
Access is denied.
Access is denied.
*** [.pio\build\esp32dev\FrameworkArduino\esp32-hal-psram.c.o] Error 1
*** [.pio\build\esp32dev\FrameworkArduino\esp32-hal-misc.c.o] Error 1
Access is denied.
*** [.pio\build\esp32dev\FrameworkArduino\esp32-hal-gpio.c.o] Error 1
Access is denied.
*** [.pio\build\esp32dev\FrameworkArduino\esp32-hal-dac.c.o] Error 1
Access is denied.
*** [.pio\build\esp32dev\FrameworkArduino\esp32-hal-bt.c.o] Error 1
Access is denied.
*** [.pio\build\esp32dev\FrameworkArduino\esp32-hal-cpu.c.o] Error 1
Access is denied.
*** [.pio\build\esp32dev\FrameworkArduino\esp32-hal-adc.c.o] Error 1
======================================================= [FAILED] Took 27.40 seconds =======================================================
The terminal process "C:\Users\zacar\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

My windows defender is turn off (temporarily) completely. This is what i get when i create a new project and try to build. After that, ALL projects do this.

I can only get a project to build correctly once if i delete the .platofrmio/packages + .platofrmio/platforms + .platofrmio/.cache folders. Then the exmaple builds, but promtply stops building as soon as i try to create a new project.

All of these files are on my C: drive -nothing is on a network drive or another drive on my machine.

this windows popup was what appened when i tried to run xtensa-esp32-elf-gcc.exe when it was 0 bytes. still it’s strange that is go corrupted again, mine is doing fine now

no matter what i do, it doesn’t work. I’ve tried everything that i can think of :frowning: rebooted my machine, checked user permissions, ran the VSCode compatalibty troubleshooter - i am hoenstly ready to reinstall windows rn.

Antivirus? Possible other things corrupting your harddrive as you try to re-download? I mean you can redownload the compiler package again (by deleting .cache and toolchain-xtensa), but it shouldn’t happen 3 times in a row that it gets corrupted…

1 Like

it’s happened every time, i have no antivirus turned on (only have windows defender on my machine). I am at a loss, i have changed nothing about my installtion, just booted up this morning to do some work and get this

if i delete the suggested folders, i can open my projects and build them. The second i create a new project - my entire platformio installation becomes corrupted. I have no idea why, nothing else on my machine is malfunctioning.

i’ve varified that my permissions are adequate - and even ran vscode as admin - still the same. I noticed that some parts of Github and a bunch of other platforms are down with a 500 error today - could the server Platformio is connecting to during the new-project-creation be malfunctioning or not able to connect to certain urls/repos?

EDIT: Alright, i installed VScode on my wifes laptop - never had ANY ide on it at all, same thing. Exact same errors, and same issue. At this point, i 100% know it is not my machine.

EDIT2: Some time later, i have solved it.

I tried vscode on another machine, same thing. However, when I logged out of my account on the other machine, disabled all extensions but the platformio and c++ extensions required by pio - the issue STILL happened. This told me it was not my machines - but something wrong with my extensions, so I went and checked the c++ extension - it was on the pre-release version. I switched to the release version - problem solved (for now). I am absolutely positive this was the cause of the issue. I tried everything prior, reinstalling vscode, reinstalling platformio (10 times might I add), checking user permissions, disabling windows defender, etc etc. Nothing worked. Check your c++ extension and ensure that it is on the ´release´ version, not the ´pre-release´. Then, delete the contents of the ´.platformio/packages´, ´.platformio/platforms´, ´.platformio/.cache´ folders and rebuild the project.

5 Likes

This works indeed, thank you for posting the solution…

1 Like

Is today harddrive corruption / antivirus goes berserk day? It’s extremely unusual to have that high of a concentration of “my PlatformIO build just broke” posts o_O

“… Check your c++ extension and ensure that it is on the ´release´ version, not the ´pre-release´. Then, delete the contents of the ´.platformio/packages´, ´.platformio/platforms´, ´.platformio/.cache´ folders and rebuild the project.”

Yes this seems to work. You may get an error as it takes time to rebuild and you may have to do it for every project.

seems like it, haha. I am still trying to figure out when my vscode switched to the pre-release version of the c/c++ extension. I’d never consciously do that, very weird. The generated junk files was also especially weird, never expereinced this kind of bug before. Hopefully ya’ll (platformio staff) get this squared away. Please, let us (community) know what we can do to assist.

1 Like

Thx a lot @zanzythebar
your solution works fine

1 Like

I keep running into this error /.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: cannot find Inc\Documents\Arduino\TestESP32\.pio\build\adafruit_feather_esp32s3_tft\firmware.map: No such file or directory collect2.exe: error: ld returned 1 exit status *** [.pio\build\adafruit_feather_esp32s3_tft\firmware.elf] Error 1

And I’ve deleted all the folders as well as disable all extensions and check C++ version. Anyone have a fix for this?