Undefined reference to 'WinMain@16' C error

女生的网名这么多〃 提交于 2020-01-03 18:51:51

问题


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

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/13459912/undefined-reference-to-winmain16-c-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!