I'm writing my first C++ program on Windows 11. The code only includes , prints two lines, and returns 0, so it seems valid. However, every time I compile it, I get this linker error:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/16.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/16.2.0/liblto_plugin.dll: error loading plugin
collect2.exe: error: ld returned 1 exit status
I installed the compiler by following a tutorial, but I'm not sure whether it was configured correctly or how the compiler and linker are being invoked. What should I check to resolve this?
2 Answers
The C++ code itself looks valid. The final line only reports that the linker failed; the important clue is the earlier message saying that liblto_plugin.dll could not be loaded. Check the complete compiler output and verify that your MSYS2/MinGW installation is configured correctly and that you’re using the intended compiler and linker paths.
This turned out to be a Windows security setting rather than a problem with the program. Disabling Smart App Control under Windows Security > App & browser control allowed the linker plugin to load and fixed the build.

The full output points to an error loading liblto_plugin.dll from the MSYS2 MinGW directory.