-1
#include<stdio.h>
void display(); //Functon prototype

    int main(){
  
    printf("Initializing display function\n");
      display();
      printf("Display function finished\n");
    return 0;
}

void display(){
    printf("This is display\n");
}

Here is the error message please help me to solve this:-

PS D:\C Tutorial> gcc 05_function.c                                   
}
C:/MinGW/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.1.0/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o32_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x39):
undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1
exit status 
PS D:\C Tutorial>
Gerhardh
  • 11,688
  • 4
  • 17
  • 39
  • PS D:\C Tutorial> gcc 05_function.c } C:/MinGW/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.1.0/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o32_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x39): undefined reference to `WinMain@16' collect2.exe: error: ld returned 1 exit status PS D:\C Tutorial> – Mithlesh Kumar Dec 17 '21 at 10:30
  • 3
    Does this answer your question? [undefined reference to \`WinMain@16'](https://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16) – Mark Benningfield Dec 17 '21 at 10:37
  • 1
    Did you set up your project as a console program? – the busybee Dec 17 '21 at 10:38

3 Answers3

0

If you are using a text editor without autosave, this can happen.

Try saving your code and running it again.

If you are using VSCode, I'd recommend enabling autosave.

Hope I could help!

Mukul Aryal
  • 56
  • 1
  • 7
0

This error occurs when we try to compile an empty file. Saving the file and then compiling it will help in this.

Girija
  • 118
  • 3
0

Problem statement:

Here we found the error in the program is that the code is working fine in the editor or online compiler, but i think you didnt save the code or any important thing is missing in the editor.

Alternate solution:

One more reason is even if you have written the main function but if you didnot save the .cpp file and try to compile it will give the same error.So make sure you have successfully saved the .cpp file and then compile and run your code.

Hope this will help since I have faced similar issue and I spent around hours to figure it out , Thanks.

I would like to add the code and its output for your reference. Code with Output picture in this link.