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.

1 Like

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.

Thanks for your post! I ran exactly into the same issue and after a lot googling I finally came across your post. Will try it right away!
Take it as a confirmation for your “post in case anybody else is currently struggling with this issue” :smile:

1 Like

Now, I installed MinGW via chocolatey (great tip, btw!) which installed mingw13.2 - same issue in platform.IO (archive has no index)
After installing MinGW 12.2 testing works!
Conclusion: MinGW 13.2 seems not to work with platform.IO; 12.2 has to be used.
Issue filed at github under platformio/platform-native/issues/25

1 Like

I have 12.2 from MSYS2 and it doesn’t work. It used to but maybe I had different set of env paths configured.

Anyway, I installed 13.2 from choco (choco install mingw), restarted vscode and pio test started to work immediately.

Choco seems so convenient. Can I get rid of MSYS2 already? :smiley: