Strange "archive has no index" error when unit testing on native with Mingw-w64 installed via MSYS2

Got the following strange error when trying to run the unit tests on the platformio calculator example while figuring out how to do unit tests on native.

C:/msys64/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/13.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: .pio\build\native\lib49a\libcalculator.a: error adding symbols: archive has no index; run ranlib to add one
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\native\program.exe] Error 1
Building stage has failed, see errors above. Use pio test -vvv option to enable verbose output.

I had installed Mingw via MSYS2 following their installation documentation. Couldn’t figure out what the heck was wrong that would cause this strange error, but suspected some issue with the compiler, so eventually uninstalled MSYS2 and all packages.

Then I installed MinGW via chocolatey which at writing using Mingw 12.2 (via MSYS2, version was 13.2). This solved the error and tests began to run without issue.

Not sure if anybody knows what the issue here is. Maybe it was an installation mistake on my part via MSYS2, or if it actually is the version that makes the difference. Either way, it is working for me now and thought I would make a post in case anybody else is currently struggling with this issue.

Usually PlatformIO has a “Generating archive index” step which exactly executes ranlib or gcc-ranlib, but this does not seem to be happening for platform = native (?).

Please file a bug in Issues · platformio/platform-native · GitHub.