I get exactly the same errors when I try to compile LLaMA.cpp with MSYS2.
ld.exe: cannot find -lC:/msys64/ucrt64/lib/libgomp.dll.a: Invalid argument
ld.exe: cannot find -lC:/msys64/ucrt64/lib/libmingwthrd.a: Invalid argument
I found this workaround: Before to run the compilation (cmake --build build ...), I edit the file build/CmakeCache.txt generated by cmake and replace the absolute Windows path C:/msys64/ucrt64/lib/libmingwthrd.a by the absolute path of the same file when you run the msys console : /ucrt64/lib/libmingwthrd.a
And the same for C:/msys64/ucrt64/lib/libgomp.dll.a --> /ucrt64/lib/libgomp.dll.a