简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM