PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, June 26, 2022

[FIXED] Why does the "collect2.exe: error: ld returned 1 exit status" keep coming?

 June 26, 2022     c, compiler-errors, runtime-error     No comments   

Issue

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

Solution

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;
}


Answered By - shrey deshwal
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing