Yanika Abela
Yanika Abela

Reputation: 55

Undefined reference to 'WinMain@16' C error

I am using Eclipse (C programming) and I have come up with this code but every time I build it, I get the error saying, "Undefined Reference to 'WinMain@16'". I have spent over 2 hours trying to solve this problem but I can't figure out my where my error is. Can anyone help?

This is the code:

#include <stdio.h> 

int main(void)
{
    int input;

    printf("Please enter an integer:\n");
    scanf("%d",&input);
    int temp = input;

    while(input<=temp+10)
    {
        printf("%d ",input);
        input++;
    }

    printf("\n");

    return 0;
}

Upvotes: 4

Views: 13643

Answers (2)

huysentruitw
huysentruitw

Reputation: 28111

When you compile or build, files are not automatically saved to disk by Eclipse. But the compiler is using the on-disk files. So maybe you just didn't save the file after you've added the main function.

Upvotes: 7

Toribio
Toribio

Reputation: 4078

If you are compiling the right and saved file, you have to make sure you are compiling it with the subsystem target set to console, when you're using the main entry point.

You can do this changing the makefile.

If you don't know how to do this, or if you're not using a makefile and don't want to change the compiler's parameters line, you can use this directive:

#pragma comment(linker, "/subsystem:console")

WinMain is normally used for /subsystem:windows type of programs, and as you are trying to make a console application, you should use /subsystem:console and the main entry point.

Again, make sure you are compiling the right file on the disk.

Upvotes: 0

Related Questions