Search code examples
c++sublimetext3mingw

MinGW: Internal error when building a C++ program


I had been running C++ programs with G++17 quite comfortably, when one day for no apparent reason, this error shows up:

internal error in mingw32_gt_pch_use_address, at config/i386/host-mingw32.c:190: MapViewOfFileEx: Attempt to access invalid address.

Below is the complete error output:

[Finished in 4.5s with exit code 1]
[cmd: ['g++.exe', '-std=c++17', '-D DIV_DEBUG', 'D:\\Codes\\code.cpp', '-o', 'code.exe', '&&', 'code.exe<inputf.in>outputf.in']]
[dir: D:\Codes]
[path: C:\Python38\Scripts\;C:\Python38\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\MinGW\bin;C:\ProgramData\pbox;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Users\asus\AppData\Local\Microsoft\WindowsApps;C:\Users\asus\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;C:\tools;C:\Users\asus\AppData\Roaming\npm;C:\Users\asus\AppData\Local\atom\bin]

I've been searching for a solution for three days now and haven't found it yet. It looks like a bug in MinGW but I do not know how to fix this. My last option is to delete everything related to MinGW and reinstall it. Any better ideas are appreciated.

The code which I'm trying to compile.

#include <bits/stdc++.h>

int main() {
    std::cout << "Hello, World!\n";
    return 0;
}

It appears that removing the "bits/stdc++.h" header file removes this error. I would still like to know how I can fix this as I use this library on a daily basis for all my programs.

Edit: I tried building on Windows Powershell but the same error comes up.

PS D:\Codes> g++.exe -std=c++17 -D DIV_DEBUG code.cpp -o code.exe
internal error in mingw32_gt_pch_use_address, at config/i386/host-mingw32.c:190: MapViewOfFileEx: Attempt to access invalid address.

Update: Tried reinstalling MinGW. It didn't work.


Solution

  • Okay, so the issue went as miraculously as it had appeared. I precompiled the header files after reinstalling MinGW and for some reason, it fixed the issue. I'm not sure if this action triggered the fix.

    If someone can throw some light on this strange behaviour, I would mark that answer as accepted.