Why does my C++ program fail with “collect2.exe: error: ld returned 1 exit status” on Windows 11?

September 2, 2026 2 answers
Asked by MellowCedar42
I'm writing my first C++ program on Windows 11. The code only includes , prints two messages, and returns 0, so it seems valid. However, every time I compile it, I get this linker error: "ld.exe: .../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 my compiler or linker configuration is correct. What should I check, and what does this error mean?

Answers

QuartzMango18
This can happen when Windows security blocks one of the compiler’s DLL files. The issue was resolved by disabling Smart App Control under Windows Security → App & browser control, allowing the linker plugin to load. Be careful when changing security settings, though—ideally confirm that the compiler came from a trusted source, and consider repairing or reinstalling the toolchain if possible.
Reply to this answer
PixelHarbor7
The C++ code itself looks fine. The line about collect2.exe is only the final summary, so the important part is the earlier error message. In this case, the linker specifically says it could not load liblto_plugin.dll, which points to a compiler installation, environment, or Windows security issue rather than a problem with the program. It would also help to know the exact command you’re using to compile it and which toolchain is installed.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions