How can I fix the “ld returned 1 exit status” error in C++ on Windows?

0
28
Asked By VelvetMango42 On

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

Answered By QuietRiver7 On

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.

VelvetMango42 -

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

Answered By CopperLark19 On

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.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.