Compilation error in Windows when compiling C code: "cannot find -lgcc" and "ld returned 1 exit status"

312 Views Asked by At

I'm encountering an issue when compiling my C code in Windows. The file name is main.c, and I'm using MinGW's GCC compiler.

I receive a error whether I execute:

  • gcc main.c
  • gcc -o main main.c -lgcc -lgcc_eh
  • Compile the code in VSCode

I receive the following error message along with a "Error Compiling" flag:

c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lgcc
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lgcc_eh
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lgcc
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lgcc_eh
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lgcc
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lgcc_eh
collect2.exe: error: ld returned 1 exit status

I'm seeking assistance to understand why these errors occur and how to resolve them. I have already installed MinGW and have the necessary environment variables set up correctly. Any insights or suggestions on resolving this issue would be greatly appreciated.

Thank you in advance!

I verified that MinGW is installed on my Windows system by running gcc -v in the command prompt. The version information was displayed correctly. I ensured that the MinGW installation directory (e.g., C:\mingw\bin) is added to the system's PATH environment variable. To address the "cannot find -lgcc" and "cannot find -lgcc_eh" errors, I tried updating the MinGW libraries (I executed mingw-get update and mingw-get upgrade) but without any result.

I am expecting Windows to compile C code successfully without any error.

0

There are 0 best solutions below