Home > Enterprise >  Why does the "collect2.exe: error: ld returned 1 exit status" keep coming?
Why does the "collect2.exe: error: ld returned 1 exit status" keep coming?

Time:10-31

I'm a beginner in Coding. I'm trying to write a code in C. Uptill this code every code was running smoothly. But after writing the following code the Visual Studio Code is giving errors. The most repeated was collect2.exe: error: ld returned 1 exit status. I saved the code before running. I tried reinstalling the gcc MinGW compiler and Visual Studio Code IDE but nothing happened. I also tried the Geany IDE but it is showing the same error. What should I do?

    #include<stdio.h>
    #include<stdlib.h>

    int mian(){
         int marks[4];
         marks[0]=34;
         printf("Marks of Student 4 is %d",marks[0]);
         return 0;
    }

PS D:\Codes> cd "d:\Codes\CPrograms\" ; if ($?) { gcc arrays.c -o arrays } ; if ($?) { .\arrays }
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup 0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status

CodePudding user response:

Error: Id returned 1 exit status (undefined reference to 'main') 

This error is occurred on following cases,

  1. If main() is not written in lowercase, like you used Main(), MAIN(), mAin() or anything else.
  2. If main() does not exist in the program or by mistake you mistyped the main().

In your case you mistyped the main() change mian()--> main()

#include<stdio.h>
#include<stdlib.h>

int main(){
     int marks[4];
     marks[0]=34;
     printf("Marks of Student 4 is %d",marks[0]);
     return 0;
}
  • Related