It turned out that the problem was related to the PATH variable.
The executable was successfully linked with a DLL on the search path in MSYS2, but the PATH variable for the system (the one used for the cmd utility) did not include this folder. Fixing this led to successful execution of the code.