I recompiled one of my codes using a freshly installed MSYS2 with the (default) UCRT64 environment, and it behaves weirdly: debug version works, but release version dies on opening an ifstream
– regardless if the file exists or not – or maybe it just stops writing output; in any case, a cout
placed on the following line does not appear (and there is no exception either).
I have then tried the following minimal code:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
auto const tgFName = "normal_3d_corrs.dat";
cout << "TEST 1: trying to open `" << tgFName << "'" << endl;
std::ifstream tgCorrStr(tgFName, std::ifstream::in);
cout << "TEST 2: " << "stream status: " << tgCorrStr.good() <<", " << tgCorrStr.fail() << ", " << tgCorrStr.is_open() << endl;
return (tgCorrStr.good() ? 0 : 1);
}
Compiled with g++ test.cpp -o test.exe
from the MSYS2 UCRT64 terminal, it produces test.exe
without any warnings.
However, running test.exe
in the standard Windows terminal (cmd) does not produce any output at all, regardless of whether the test file exists or not. Unlike the original case, debug mode (adding -g
) does not make any difference.
It works as expected when compiled using Visual Studio’s cl
or gcc
in Ubuntu on WSL.
I cannot believe that MSYS2 would be that broken, so I assume the problem is on my side – but I have no idea what it could be…
System info:
I am running 64-bit Windows 10. It is a company computer with rather strict security settings, in case it should matter.
I had a problem installing MSYS2 and had to disable two Exploit protection
security settings, as described here. I kept these disabled and even disabled further two settings suggested in this thread, but it did not help.